refactor(backend): 启动环境初始化与资源项目化(零跨项目依赖)
- main.py:uv run main.py 一键启动——读取 backend/.env、TORCH_HOME/NLTK_DATA 指向项目内缓存、certifi SSL + NO_PROXY 网络直连、默认开启 s2s,启动横幅 - vendor/:补丁后 s2s 云化栈移入项目(backend/vendor/s2s-cloud),pyproject sources 改相对路径 - .gitignore:忽略 .torch-cache / nltk_data 缓存 - AGENTS.md:进程管理铁律(AI 不启动/重启服务,由用户操作)
This commit is contained in:
+37
@@ -0,0 +1,37 @@
|
||||
// @ts-check
|
||||
/** Small shared helpers used across the UI modules: a strict query selector,
|
||||
* HTML escaping for text we drop into innerHTML, error-string trimming, and
|
||||
* the opt-in debug flag. */
|
||||
|
||||
/** Opt-in tracing: `localStorage.setItem("s2s.debug", "1")` then reload. */
|
||||
export const DEBUG = (() => {
|
||||
try {
|
||||
return localStorage.getItem("s2s.debug") === "1";
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
})();
|
||||
|
||||
/**
|
||||
* Query a single element, throwing if it's missing (so a broken selector fails
|
||||
* loudly at startup rather than as a later null-deref).
|
||||
* @template {HTMLElement} T
|
||||
* @param {string} selector
|
||||
* @returns {T}
|
||||
*/
|
||||
export function $(selector) {
|
||||
const el = document.querySelector(selector);
|
||||
if (!el) throw new Error(`Missing element: ${selector}`);
|
||||
return /** @type {T} */ (el);
|
||||
}
|
||||
|
||||
/** @param {string} s @returns {string} */
|
||||
export function escHtml(s) {
|
||||
return s.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
||||
}
|
||||
|
||||
/** Trim a long error message to fit the orb caption. @param {string} text */
|
||||
export function truncateError(text) {
|
||||
if (text.length <= 90) return text;
|
||||
return text.slice(0, 87) + "…";
|
||||
}
|
||||
Reference in New Issue
Block a user