From a1754feaf3bda1bfc62abe2709a903ff45e6812b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E6=BD=AE?= Date: Thu, 21 May 2026 18:30:01 +0800 Subject: [PATCH] static-hosting --- skills/linggan/static-hosting/SKILL.md | 74 +++---------------- .../linggan/static-hosting/scripts/get_url.py | 25 +++++++ 2 files changed, 37 insertions(+), 62 deletions(-) create mode 100644 skills/linggan/static-hosting/scripts/get_url.py diff --git a/skills/linggan/static-hosting/SKILL.md b/skills/linggan/static-hosting/SKILL.md index 7d74b21..8b54686 100644 --- a/skills/linggan/static-hosting/SKILL.md +++ b/skills/linggan/static-hosting/SKILL.md @@ -5,75 +5,25 @@ description: Serve static HTML/CSS/JS/images from robot project directories via # Static Hosting -Provide external access to static files (HTML, CSS, JS, images, fonts, etc.) stored under each robot's project directory. +Host static files (HTML, CSS, JS, images, fonts, etc.) under the bot's project directory and get public URLs. -## Use when +## Usage -- Generate HTML pages, reports, or dashboards for a bot and need a URL to access them -- Create interactive web content (with CSS/JS) that users can open in a browser -- Need to host images or other assets referenced by bot-generated HTML +Write files to `/app/projects/robot/{ASSISTANT_ID}/`, then run the script to get the public URL: -## How it works - -FastAPI mounts `projects/robot/` at the `/robots` URL path with `html=True` enabled. - -``` -/app/projects/robot/{bot_id}/ --> {FASTAPI_URL}/robots/{bot_id}/ -/app/projects/robot/{bot_id}/foo.html --> {FASTAPI_URL}/robots/{bot_id}/foo.html +```bash +python3 {SKILL_DIR}/scripts/get_url.py ``` -`FASTAPI_URL` : `https://engine.aitravelmaster.com`. - -## URL rules - -| Local path | External URL | Notes | -|---|---|---| -| `/app/projects/robot/{bot_id}/index.html` | `/robots/{bot_id}/` | `html=True` auto-resolves `index.html` | -| `/app/projects/robot/{bot_id}/page.html` | `/robots/{bot_id}/page.html` | Direct HTML access | -| `/app/projects/robot/{bot_id}/css/style.css` | `/robots/{bot_id}/css/style.css` | CSS files | -| `/app/projects/robot/{bot_id}/js/app.js` | `/robots/{bot_id}/js/app.js` | JavaScript files | -| `/app/projects/robot/{bot_id}/images/logo.png` | `/robots/{bot_id}/images/logo.png` | Images (png/jpg/svg/etc.) | -| `/app/projects/robot/{bot_id}/fonts/custom.woff2` | `/robots/{bot_id}/fonts/custom.woff2` | Font files | - -## Recommended directory structure +Example: +```bash +python3 {SKILL_DIR}/scripts/get_url.py /app/projects/robot/{ASSISTANT_ID}/index.html +# => https://engine.aitravelmaster.com/robots/[bot-id]/index.html ``` -/app/projects/robot/{bot_id}/ -├── index.html # Entry page (auto-served at /robots/{bot_id}/) -├── css/ -│ └── style.css -├── js/ -│ └── app.js -├── images/ -│ └── logo.png -└── fonts/ - └── custom.woff2 -``` - -## HTML referencing rules - -Inside HTML files, use **relative paths** to reference local assets: - -```html - - - -logo -``` - -Do NOT use absolute paths like `/css/style.css` — this would resolve to the server root, not the bot directory. - -## Quick example - -To generate and serve a simple page for bot `63069654-7750-409d-9a58-a0960d899a20`: - -1. Write HTML to `/app/projects/robot/63069654-7750-409d-9a58-a0960d899a20/index.html` -2. Access at `{FASTAPI_URL}/robots/63069654-7750-409d-9a58-a0960d899a20/` ## Notes -- Content-Type is auto-detected from file extension -- CORS is already configured (allow all origins) so frontend JS can fetch APIs on the same server -- Subdirectories of any depth are supported -- No authentication — all files under `/robots/` are publicly accessible -- The mount is defined in `fastapi_app.py` +- Inside HTML, use **relative paths** to reference other assets (e.g. `href="css/style.css"`) +- `index.html` is auto-served at the directory URL +- All files under `/robots/` are publicly accessible, no authentication diff --git a/skills/linggan/static-hosting/scripts/get_url.py b/skills/linggan/static-hosting/scripts/get_url.py new file mode 100644 index 0000000..e7c22a7 --- /dev/null +++ b/skills/linggan/static-hosting/scripts/get_url.py @@ -0,0 +1,25 @@ +import os +import sys + +FASTAPI_URL = os.getenv("FASTAPI_URL", "https://engine.aitravelmaster.com") +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]} /app/projects/robot/{ASSISTANT_ID}/index.html") + sys.exit(1) + +file_path = os.path.abspath(sys.argv[1]) + +workspace_root = f"/app/projects/robot/{ASSISTANT_ID}" +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"{FASTAPI_URL.rstrip('/')}/robots/{ASSISTANT_ID}" +print(f"{base_url}{relative_path}")