YYP0502 commited on
Commit
ad2d867
·
verified ·
1 Parent(s): 26d5fc7

Delete scripts

Browse files
scripts/configure_codex.py DELETED
@@ -1,22 +0,0 @@
1
- import json
2
- import os
3
- from pathlib import Path
4
-
5
- home = Path(os.environ["CODEX_HOME"])
6
- home.mkdir(parents=True, exist_ok=True)
7
- provider = "qqbridge"
8
- base = os.environ["CODEX_BASE_URL"]
9
- model = os.environ["CODEX_MODEL"]
10
- effort = os.environ.get("CODEX_REASONING_EFFORT", "").strip()
11
- config = (
12
- f"model_provider = {json.dumps(provider)}\n"
13
- f"model = {json.dumps(model)}\n"
14
- + (f"model_reasoning_effort = {json.dumps(effort)}\n" if effort else "")
15
- + 'sandbox_mode = "danger-full-access"\n'
16
- + f"\n[model_providers.{provider}]\n"
17
- + f"name = {json.dumps(provider)}\n"
18
- + 'wire_api = "responses"\nrequires_openai_auth = false\n'
19
- + f"base_url = {json.dumps(base)}\n"
20
- + 'env_key = "CODEX_API_KEY"\n'
21
- )
22
- (home / "config.toml").write_text(config, encoding="utf-8")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
scripts/health.py DELETED
@@ -1,37 +0,0 @@
1
- import http.server
2
- import os
3
- import socket
4
- import sys
5
- from pathlib import Path
6
-
7
- PIDS = [int(p) for p in sys.argv[1:] if p.isdigit() and int(p) > 0]
8
- HEARTBEAT_FILE = Path(os.environ.get("HEARTBEAT_FILE", "/home/node/app/data/uptime-heartbeat.log"))
9
-
10
- class Handler(http.server.BaseHTTPRequestHandler):
11
- def do_GET(self):
12
- if self.path != "/health":
13
- self.send_error(404)
14
- return
15
- try:
16
- for pid in PIDS:
17
- os.kill(pid, 0)
18
- with socket.create_connection(("127.0.0.1", 8888), timeout=2):
19
- pass
20
- # One successful public health request produces exactly one byte.
21
- HEARTBEAT_FILE.parent.mkdir(parents=True, exist_ok=True)
22
- with HEARTBEAT_FILE.open("a", encoding="ascii") as heartbeat:
23
- heartbeat.write(".")
24
- heartbeat.flush()
25
- status, body = 200, b"ok\n"
26
- except OSError:
27
- status, body = 503, b"unavailable\n"
28
- self.send_response(status)
29
- self.send_header("Content-Type", "text/plain")
30
- self.send_header("Cache-Control", "no-store")
31
- self.send_header("Content-Length", str(len(body)))
32
- self.end_headers()
33
- self.wfile.write(body)
34
- def log_message(self, *_):
35
- pass
36
-
37
- http.server.ThreadingHTTPServer(("127.0.0.1", 7861), Handler).serve_forever()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
scripts/show_logs.py DELETED
@@ -1,16 +0,0 @@
1
- import os
2
- import sys
3
- from pathlib import Path
4
-
5
- for filename in sys.argv[1:]:
6
- path = Path(filename)
7
- if not path.is_file():
8
- continue
9
- lines = path.read_text(encoding="utf-8", errors="replace").splitlines()[-40:]
10
- secrets = [os.environ.get(name, "") for name in ("JUPYTER_TOKEN", "CODEX_API_KEY", "QQBOT_APP_SECRET", "QQBOT_APP_ID")]
11
- print(f"--- {path.name} (last {len(lines)} lines, secrets redacted) ---")
12
- for line in lines:
13
- for secret in secrets:
14
- if secret:
15
- line = line.replace(secret, "[REDACTED]")
16
- print(line[:1000])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
scripts/start.sh DELETED
@@ -1,62 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -Eeuo pipefail
3
- cd /home/node/app
4
- mkdir -p data workspace /tmp/nginx
5
- # Both chat history and Codex/Jupyter working files are ephemeral.
6
- find workspace -mindepth 1 -maxdepth 1 -exec rm -rf -- {} +
7
- rm -f data/history.json data/bridge.log data/codex-*.txt data/jupyter.log data/nginx.log data/startup.log data/health.log data/uptime-heartbeat.log
8
- touch data/uptime-heartbeat.log
9
- export HEARTBEAT_FILE=/home/node/app/data/uptime-heartbeat.log
10
- exec > >(tee -a data/startup.log) 2>&1
11
- : "${JUPYTER_TOKEN:?Set JUPYTER_TOKEN in Space Secrets to access JupyterLab}"
12
- printf '%s startup begin\n' "$(date -Is)"
13
-
14
- export CODEX_HOME=/home/node/app/data/codex-home
15
- mkdir -p "$CODEX_HOME/skills"
16
- cp -r /home/node/app/skills/. "$CODEX_HOME/skills/"
17
-
18
- # Start Jupyter first. A bad bot/model configuration must not make the Space UI unavailable.
19
- jupyter lab --ip=127.0.0.1 --port=8888 --no-browser \
20
- --ServerApp.root_dir=/home/node/app/workspace \
21
- --ServerApp.token="${JUPYTER_TOKEN}" \
22
- --ServerApp.password='' \
23
- --ServerApp.allow_remote_access=True \
24
- --ServerApp.trust_xheaders=True \
25
- --ServerApp.base_url=/ > data/jupyter.log 2>&1 &
26
- jupyter_pid=$!
27
- printf '%s jupyter pid=%s\n' "$(date -Is)" "$jupyter_pid"
28
-
29
- python3 scripts/health.py "$jupyter_pid" > data/health.log 2>&1 &
30
- health_pid=$!
31
- nginx -c /home/node/app/nginx.conf -g 'daemon off;' > data/nginx.log 2>&1 &
32
- nginx_pid=$!
33
-
34
- bot_pid=''
35
- required=(QQBOT_APP_ID QQBOT_APP_SECRET QQ_ALLOWED_OPENIDS CODEX_BASE_URL CODEX_API_KEY CODEX_MODEL JUPYTER_TOKEN)
36
- missing=()
37
- for name in "${required[@]}"; do [[ -n "${!name:-}" ]] || missing+=("$name"); done
38
- if ((${#missing[@]})); then
39
- printf '%s bot not started; missing variables: %s\n' "$(date -Is)" "${missing[*]}" | tee -a data/bridge.log
40
- else
41
- python3 scripts/configure_codex.py
42
- codex --version | tee -a data/bridge.log
43
- node dist/index.js > data/bridge.log 2>&1 &
44
- bot_pid=$!
45
- printf '%s bot pid=%s started\n' "$(date -Is)" "$bot_pid" | tee -a data/bridge.log
46
- fi
47
-
48
- cleanup() {
49
- trap - EXIT INT TERM
50
- for pid in "$nginx_pid" "$health_pid" "$bot_pid" "$jupyter_pid"; do
51
- [[ -n "$pid" ]] && kill "$pid" 2>/dev/null || true
52
- done
53
- wait 2>/dev/null || true
54
- }
55
- trap cleanup EXIT
56
- trap 'exit 0' INT TERM
57
- while kill -0 "$jupyter_pid" 2>/dev/null && kill -0 "$nginx_pid" 2>/dev/null; do
58
- sleep 5
59
- done
60
- printf '%s jupyter or nginx exited; container will restart\n' "$(date -Is)"
61
- python3 scripts/show_logs.py data/jupyter.log data/nginx.log data/bridge.log
62
- exit 1