refactor: move frontend apps to frontends/ and fix path references
This commit is contained in:
@@ -94,7 +94,7 @@ def require_runtime(agent, label, **required):
|
|||||||
|
|
||||||
|
|
||||||
def redirect_log(script_file, log_name, label, allowed):
|
def redirect_log(script_file, log_name, label, allowed):
|
||||||
log_dir = os.path.join(os.path.dirname(script_file), "temp")
|
log_dir = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(script_file))), "temp")
|
||||||
os.makedirs(log_dir, exist_ok=True)
|
os.makedirs(log_dir, exist_ok=True)
|
||||||
logf = open(os.path.join(log_dir, log_name), "a", encoding="utf-8", buffering=1)
|
logf = open(os.path.join(log_dir, log_name), "a", encoding="utf-8", buffering=1)
|
||||||
sys.stdout = sys.stderr = logf
|
sys.stdout = sys.stderr = logf
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import asyncio, json, os, sys, threading, time
|
import asyncio, json, os, sys, threading, time
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||||
from agentmain import GeneraticAgent
|
from agentmain import GeneraticAgent
|
||||||
from chatapp_common import AgentChatMixin, ensure_single_instance, public_access, redirect_log, require_runtime, split_text
|
from chatapp_common import AgentChatMixin, ensure_single_instance, public_access, redirect_log, require_runtime, split_text
|
||||||
from llmcore import mykeys
|
from llmcore import mykeys
|
||||||
@@ -1,22 +1,14 @@
|
|||||||
import glob
|
import glob, json, os, queue as Q, re, sys, threading, time
|
||||||
import json
|
|
||||||
import os
|
|
||||||
import queue as Q
|
|
||||||
import re
|
|
||||||
import sys
|
|
||||||
import threading
|
|
||||||
import time
|
|
||||||
|
|
||||||
PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))
|
PROJECT_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||||
sys.path.insert(0, PROJECT_ROOT)
|
sys.path.insert(0, PROJECT_ROOT)
|
||||||
os.chdir(PROJECT_ROOT)
|
os.chdir(PROJECT_ROOT)
|
||||||
|
from agentmain import GeneraticAgent
|
||||||
|
from llmcore import mykeys
|
||||||
|
|
||||||
import lark_oapi as lark
|
import lark_oapi as lark
|
||||||
from lark_oapi.api.im.v1 import *
|
from lark_oapi.api.im.v1 import *
|
||||||
|
|
||||||
from agentmain import GeneraticAgent
|
|
||||||
from llmcore import mykeys
|
|
||||||
|
|
||||||
_TAG_PATS = [r"<" + t + r">.*?</" + t + r">" for t in ("thinking", "summary", "tool_use", "file_content")]
|
_TAG_PATS = [r"<" + t + r">.*?</" + t + r">" for t in ("thinking", "summary", "tool_use", "file_content")]
|
||||||
_IMAGE_EXTS = {".png", ".jpg", ".jpeg", ".gif", ".bmp", ".webp", ".ico", ".tiff", ".tif"}
|
_IMAGE_EXTS = {".png", ".jpg", ".jpeg", ".gif", ".bmp", ".webp", ".ico", ".tiff", ".tif"}
|
||||||
_AUDIO_EXTS = {".opus", ".mp3", ".wav", ".m4a", ".aac"}
|
_AUDIO_EXTS = {".opus", ".mp3", ".wav", ".m4a", ".aac"}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import asyncio, os, sys, threading, time
|
import asyncio, os, sys, threading, time
|
||||||
from collections import deque
|
from collections import deque
|
||||||
|
|
||||||
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||||
from agentmain import GeneraticAgent
|
from agentmain import GeneraticAgent
|
||||||
from chatapp_common import AgentChatMixin, ensure_single_instance, public_access, redirect_log, require_runtime, split_text
|
from chatapp_common import AgentChatMixin, ensure_single_instance, public_access, redirect_log, require_runtime, split_text
|
||||||
from llmcore import mykeys
|
from llmcore import mykeys
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
import os, sys, re, threading, asyncio, queue as Q, socket, time
|
import os, sys, re, threading, asyncio, queue as Q, socket, time
|
||||||
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||||
from agentmain import GeneraticAgent
|
from agentmain import GeneraticAgent
|
||||||
try:
|
try:
|
||||||
from telegram import Update
|
from telegram import Update
|
||||||
@@ -120,7 +120,7 @@ if __name__ == '__main__':
|
|||||||
if not ALLOWED:
|
if not ALLOWED:
|
||||||
print('[Telegram] ERROR: tg_allowed_users in mykey.py is empty or missing. Set it to avoid unauthorized access.')
|
print('[Telegram] ERROR: tg_allowed_users in mykey.py is empty or missing. Set it to avoid unauthorized access.')
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
_logf = open(os.path.join(os.path.dirname(__file__), 'temp', 'tgapp.log'), 'a', encoding='utf-8', buffering=1)
|
_logf = open(os.path.join(os.path.dirname(os.path.dirname(__file__)), 'temp', 'tgapp.log'), 'a', encoding='utf-8', buffering=1)
|
||||||
sys.stdout = sys.stderr = _logf
|
sys.stdout = sys.stderr = _logf
|
||||||
print('[NEW] New process starting, the above are history infos ...')
|
print('[NEW] New process starting, the above are history infos ...')
|
||||||
threading.Thread(target=agent.run, daemon=True).start()
|
threading.Thread(target=agent.run, daemon=True).start()
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import asyncio, os, sys, threading
|
import asyncio, os, sys, threading
|
||||||
from collections import deque
|
from collections import deque
|
||||||
|
|
||||||
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||||
from agentmain import GeneraticAgent
|
from agentmain import GeneraticAgent
|
||||||
from chatapp_common import AgentChatMixin, ensure_single_instance, public_access, redirect_log, require_runtime, split_text
|
from chatapp_common import AgentChatMixin, ensure_single_instance, public_access, redirect_log, require_runtime, split_text
|
||||||
from llmcore import mykeys
|
from llmcore import mykeys
|
||||||
22
launch.pyw
22
launch.pyw
@@ -2,6 +2,9 @@ import webview, threading, subprocess, sys, time, os, ctypes, atexit, socket, ra
|
|||||||
|
|
||||||
WINDOW_WIDTH, WINDOW_HEIGHT, RIGHT_PADDING, TOP_PADDING = 600, 900, 0, 100
|
WINDOW_WIDTH, WINDOW_HEIGHT, RIGHT_PADDING, TOP_PADDING = 600, 900, 0, 100
|
||||||
|
|
||||||
|
script_dir = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
frontends_dir = os.path.join(script_dir, "frontends")
|
||||||
|
|
||||||
def find_free_port(lo=18501, hi=18599):
|
def find_free_port(lo=18501, hi=18599):
|
||||||
ports = list(range(lo, hi+1)); random.shuffle(ports)
|
ports = list(range(lo, hi+1)); random.shuffle(ports)
|
||||||
for p in ports:
|
for p in ports:
|
||||||
@@ -15,8 +18,7 @@ def get_screen_width():
|
|||||||
|
|
||||||
def start_streamlit(port):
|
def start_streamlit(port):
|
||||||
global proc
|
global proc
|
||||||
script_dir = os.path.dirname(os.path.abspath(__file__))
|
cmd = [sys.executable, "-m", "streamlit", "run", os.path.join(frontends_dir, "stapp.py"), "--server.port", str(port), "--server.address", "localhost", "--server.headless", "true", "--theme.base", "dark"] # 暗黑模式
|
||||||
cmd = [sys.executable, "-m", "streamlit", "run", os.path.join(script_dir, "stapp.py"), "--server.port", str(port), "--server.address", "localhost", "--server.headless", "true", "--theme.base", "dark"] # 暗黑模式
|
|
||||||
proc = subprocess.Popen(cmd)
|
proc = subprocess.Popen(cmd)
|
||||||
atexit.register(proc.kill)
|
atexit.register(proc.kill)
|
||||||
|
|
||||||
@@ -77,36 +79,31 @@ if __name__ == '__main__':
|
|||||||
threading.Thread(target=start_streamlit, args=(port,), daemon=True).start()
|
threading.Thread(target=start_streamlit, args=(port,), daemon=True).start()
|
||||||
|
|
||||||
if args.tg:
|
if args.tg:
|
||||||
script_dir = os.path.dirname(os.path.abspath(__file__))
|
tgproc = subprocess.Popen([sys.executable, os.path.join(frontends_dir, "tgapp.py")], creationflags=subprocess.CREATE_NO_WINDOW if os.name=='nt' else 0)
|
||||||
tgproc = subprocess.Popen([sys.executable, os.path.join(script_dir, "tgapp.py")], creationflags=subprocess.CREATE_NO_WINDOW if os.name=='nt' else 0)
|
|
||||||
atexit.register(tgproc.kill)
|
atexit.register(tgproc.kill)
|
||||||
print('[Launch] Telegram Bot started')
|
print('[Launch] Telegram Bot started')
|
||||||
else: print('[Launch] Telegram Bot not enabled (use --tg to start)')
|
else: print('[Launch] Telegram Bot not enabled (use --tg to start)')
|
||||||
|
|
||||||
if args.qq:
|
if args.qq:
|
||||||
script_dir = os.path.dirname(os.path.abspath(__file__))
|
qqproc = subprocess.Popen([sys.executable, os.path.join(frontends_dir, "qqapp.py")], creationflags=subprocess.CREATE_NO_WINDOW if os.name=='nt' else 0)
|
||||||
qqproc = subprocess.Popen([sys.executable, os.path.join(script_dir, "qqapp.py")], creationflags=subprocess.CREATE_NO_WINDOW if os.name=='nt' else 0)
|
|
||||||
atexit.register(qqproc.kill)
|
atexit.register(qqproc.kill)
|
||||||
print('[Launch] QQ Bot started')
|
print('[Launch] QQ Bot started')
|
||||||
else: print('[Launch] QQ Bot not enabled (use --qq to start)')
|
else: print('[Launch] QQ Bot not enabled (use --qq to start)')
|
||||||
|
|
||||||
if args.feishu:
|
if args.feishu:
|
||||||
script_dir = os.path.dirname(os.path.abspath(__file__))
|
fsproc = subprocess.Popen([sys.executable, os.path.join(frontends_dir, "fsapp.py")], creationflags=subprocess.CREATE_NO_WINDOW if os.name=='nt' else 0)
|
||||||
fsproc = subprocess.Popen([sys.executable, os.path.join(script_dir, "fsapp.py")], creationflags=subprocess.CREATE_NO_WINDOW if os.name=='nt' else 0)
|
|
||||||
atexit.register(fsproc.kill)
|
atexit.register(fsproc.kill)
|
||||||
print('[Launch] Feishu Bot started')
|
print('[Launch] Feishu Bot started')
|
||||||
else: print('[Launch] Feishu Bot not enabled (use --feishu to start)')
|
else: print('[Launch] Feishu Bot not enabled (use --feishu to start)')
|
||||||
|
|
||||||
if args.wecom:
|
if args.wecom:
|
||||||
script_dir = os.path.dirname(os.path.abspath(__file__))
|
wcproc = subprocess.Popen([sys.executable, os.path.join(frontends_dir, "wecomapp.py")], creationflags=subprocess.CREATE_NO_WINDOW if os.name=='nt' else 0)
|
||||||
wcproc = subprocess.Popen([sys.executable, os.path.join(script_dir, "wecomapp.py")], creationflags=subprocess.CREATE_NO_WINDOW if os.name=='nt' else 0)
|
|
||||||
atexit.register(wcproc.kill)
|
atexit.register(wcproc.kill)
|
||||||
print('[Launch] WeCom Bot started')
|
print('[Launch] WeCom Bot started')
|
||||||
else: print('[Launch] WeCom Bot not enabled (use --wecom to start)')
|
else: print('[Launch] WeCom Bot not enabled (use --wecom to start)')
|
||||||
|
|
||||||
if args.dingtalk:
|
if args.dingtalk:
|
||||||
script_dir = os.path.dirname(os.path.abspath(__file__))
|
dtproc = subprocess.Popen([sys.executable, os.path.join(frontends_dir, "dingtalkapp.py")], creationflags=subprocess.CREATE_NO_WINDOW if os.name=='nt' else 0)
|
||||||
dtproc = subprocess.Popen([sys.executable, os.path.join(script_dir, "dingtalkapp.py")], creationflags=subprocess.CREATE_NO_WINDOW if os.name=='nt' else 0)
|
|
||||||
atexit.register(dtproc.kill)
|
atexit.register(dtproc.kill)
|
||||||
print('[Launch] DingTalk Bot started')
|
print('[Launch] DingTalk Bot started')
|
||||||
else: print('[Launch] DingTalk Bot not enabled (use --dingtalk to start)')
|
else: print('[Launch] DingTalk Bot not enabled (use --dingtalk to start)')
|
||||||
@@ -114,7 +111,6 @@ if __name__ == '__main__':
|
|||||||
if not args.no_sched:
|
if not args.no_sched:
|
||||||
try:
|
try:
|
||||||
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM); sock.bind(('127.0.0.1', 45762)); sock.listen(1)
|
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM); sock.bind(('127.0.0.1', 45762)); sock.listen(1)
|
||||||
script_dir = os.path.dirname(os.path.abspath(__file__))
|
|
||||||
scheduler_proc = subprocess.Popen([sys.executable, os.path.join(script_dir, "agentmain.py"), "--reflect", os.path.join(script_dir, "reflect", "scheduler.py"), "--llm_no", str(args.llm_no)], creationflags=subprocess.CREATE_NO_WINDOW if os.name=='nt' else 0);
|
scheduler_proc = subprocess.Popen([sys.executable, os.path.join(script_dir, "agentmain.py"), "--reflect", os.path.join(script_dir, "reflect", "scheduler.py"), "--llm_no", str(args.llm_no)], creationflags=subprocess.CREATE_NO_WINDOW if os.name=='nt' else 0);
|
||||||
atexit.register(lambda: (scheduler_proc.kill(), sock.close()))
|
atexit.register(lambda: (scheduler_proc.kill(), sock.close()))
|
||||||
print('[Launch] Task Scheduler started')
|
print('[Launch] Task Scheduler started')
|
||||||
|
|||||||
Reference in New Issue
Block a user