From 1d18a464c723407e6ab35e488358f84a2a562f24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E6=BD=AE?= Date: Thu, 21 May 2026 09:04:29 +0800 Subject: [PATCH] static-hosting --- skills/support/static-hosting/SKILL.md | 29 +++++++++++++++++++ .../support/static-hosting/scripts/get_url.py | 25 ++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 skills/support/static-hosting/SKILL.md create mode 100644 skills/support/static-hosting/scripts/get_url.py diff --git a/skills/support/static-hosting/SKILL.md b/skills/support/static-hosting/SKILL.md new file mode 100644 index 0000000..8a4866b --- /dev/null +++ b/skills/support/static-hosting/SKILL.md @@ -0,0 +1,29 @@ +--- +name: static-hosting +description: Serve static HTML/CSS/JS/images from robot project directories via the built-in FastAPI static file server. Use when generating web pages, reports, or interactive content for a bot. +--- + +# Static Hosting + +Host static files (HTML, CSS, JS, images, fonts, etc.) under `/workspace/` and get public URLs. + +## Usage + +Write files to `/workspace/`, then run the script to get the public URL: + +```bash +python3 {SKILL_DIR}/scripts/get_url.py +``` + +Example: + +```bash +python3 {SKILL_DIR}/scripts/get_url.py /workspace/index.html +# => https://api-dev.gptbase.ai/robot-assets/[bot-id]/index.html +``` + +## Notes + +- Inside HTML, use **relative paths** to reference other assets (e.g. `href="css/style.css"`) +- `/workspace/index.html` is auto-served at the directory URL +- All files under `/robot-assets/` are publicly accessible, no authentication diff --git a/skills/support/static-hosting/scripts/get_url.py b/skills/support/static-hosting/scripts/get_url.py new file mode 100644 index 0000000..d2c3854 --- /dev/null +++ b/skills/support/static-hosting/scripts/get_url.py @@ -0,0 +1,25 @@ +import os +import sys + +BACKEND_HOST = os.getenv("BACKEND_HOST", "https://api-dev.gptbase.ai") +ASSISTANT_ID = os.getenv("ASSISTANT_ID", "") + +if not ASSISTANT_ID: + print("Error: ASSISTANT_ID environment variable is not set") + sys.exit(1) + +if len(sys.argv) < 2: + print(f"Usage: python3 {sys.argv[0]} ") + print(f"Example: python3 {sys.argv[0]} /workspace/index.html") + sys.exit(1) + +file_path = os.path.abspath(sys.argv[1]) + +workspace_root = "/workspace" +if not file_path.startswith(workspace_root): + print(f"Error: path must be under {workspace_root}, got: {file_path}") + sys.exit(1) + +relative_path = file_path[len(workspace_root):] # e.g. "/css/style.css" +base_url = f"{BACKEND_HOST.rstrip('/')}/robot-assets/{ASSISTANT_ID}" +print(f"{base_url}{relative_path}")