mirror of
https://github.com/HKUDS/DeepTutor.git
synced 2026-12-02 15:30:06 +08:00
Security: lock down the TutorBot tool sandbox (shell exec is opt-in, all filesystem/shell access confined to the bot workspace) and isolate per-user resources, closing #518, #517, #516, #515, #514 and #506 (first hardened in #507). Bug fixes: chat input disabled after the first turn (#520), KB embedding failure on long documents (#521 / #509), profile creation under Docker (#512 / #513), Qwen reasoning models failing native tool calling (#527 / #528), the GPT-5 init-wizard token parameter (#508), and oversized session-event truncation (#524). Features: HTTP/SSE API for multi-turn chat with a specific TutorBot (#511), multimodal image fallback for vision-capable providers without a capability entry, safe ZIP knowledge upload, and a /settings/network page with model fetching (community PRs #522 and #523 reimplemented locally). Also bumps __version__ to 1.4.1, adds the v1.4.1 release notes, updates the README Releases section, and ships the Astro + Starlight docs site under site/. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
76 lines
2.2 KiB
TypeScript
76 lines
2.2 KiB
TypeScript
/**
|
|
* Cloudflare Pages Function — most recent GitHub release for HKUDS/DeepTutor.
|
|
*
|
|
* Returns the FIRST item from `/releases` (most recently published,
|
|
* including prereleases) so that `v1.4.0-beta`-style tags surface on the
|
|
* landing page immediately instead of waiting for the next stable.
|
|
*
|
|
* Optional env var:
|
|
* - GITHUB_TOKEN any read-only PAT, bumps rate limit to 5k/h.
|
|
* Not required for current traffic (unauth = 60/h, plenty
|
|
* given the 30-min edge cache).
|
|
*/
|
|
|
|
interface Env {
|
|
GITHUB_TOKEN?: string;
|
|
}
|
|
|
|
interface GithubRelease {
|
|
tag_name: string;
|
|
name: string | null;
|
|
html_url: string;
|
|
published_at: string;
|
|
prerelease: boolean;
|
|
draft: boolean;
|
|
}
|
|
|
|
const ENDPOINT =
|
|
"https://api.github.com/repos/HKUDS/DeepTutor/releases?per_page=5";
|
|
|
|
export const onRequestGet: PagesFunction<Env> = async ({ env }) => {
|
|
try {
|
|
const headers: Record<string, string> = {
|
|
Accept: "application/vnd.github+json",
|
|
"User-Agent": "deeptutor-info-pages",
|
|
"X-GitHub-Api-Version": "2022-11-28",
|
|
};
|
|
if (env.GITHUB_TOKEN) {
|
|
headers.Authorization = `Bearer ${env.GITHUB_TOKEN}`;
|
|
}
|
|
|
|
const upstream = await fetch(ENDPOINT, { headers });
|
|
if (!upstream.ok) {
|
|
return json({ error: "upstream_status", status: upstream.status }, 502);
|
|
}
|
|
|
|
const releases = (await upstream.json()) as GithubRelease[];
|
|
const latest = releases.find((r) => !r.draft) ?? null;
|
|
if (!latest) {
|
|
return json({ error: "no_release" }, 404);
|
|
}
|
|
|
|
return json(
|
|
{
|
|
tag: latest.tag_name,
|
|
name: latest.name ?? latest.tag_name,
|
|
url: latest.html_url,
|
|
published_at: latest.published_at,
|
|
prerelease: latest.prerelease,
|
|
},
|
|
200,
|
|
"public, max-age=1800, s-maxage=1800, stale-while-revalidate=3600",
|
|
);
|
|
} catch (err) {
|
|
return json({ error: "fetch_failed", detail: String(err) }, 502);
|
|
}
|
|
};
|
|
|
|
function json(body: unknown, status = 200, cache?: string): Response {
|
|
const headers: Record<string, string> = {
|
|
"Content-Type": "application/json; charset=utf-8",
|
|
"Access-Control-Allow-Origin": "*",
|
|
};
|
|
if (cache) headers["Cache-Control"] = cache;
|
|
return new Response(JSON.stringify(body), { status, headers });
|
|
}
|