diff --git a/scripts/build.ts b/scripts/build.ts index 00a8db3..3cd22bf 100644 --- a/scripts/build.ts +++ b/scripts/build.ts @@ -19,6 +19,8 @@ if (!fs.existsSync(envFile)) { console.log(`📄 已自动创建环境变量文件: ${envFile}`); } +const pkg = JSON.parse(fs.readFileSync(path.resolve("package.json"), "utf8")); + const external = [ "electron", "@huggingface/transformers", @@ -51,6 +53,9 @@ const appBuildConfig: esbuild.BuildOptions = { }, sourcemap: false, external, + define: { + __APP_VERSION__: JSON.stringify(pkg.version), + }, }; // Electron 主进程打包配置 @@ -69,6 +74,9 @@ const mainBuildConfig: esbuild.BuildOptions = { }, sourcemap: false, external, + define: { + __APP_VERSION__: JSON.stringify(pkg.version), + }, }; (async () => { diff --git a/src/agents/scriptAgent/index.ts b/src/agents/scriptAgent/index.ts index adce6f7..d322240 100644 --- a/src/agents/scriptAgent/index.ts +++ b/src/agents/scriptAgent/index.ts @@ -40,7 +40,6 @@ export async function decisionAI(ctx: AgentContext) { resTool.systemMessage("决策层AI 接管聊天"); const memory = new Memory("scriptAgent", isolationKey); - console.log("%c Line:43 🥟 isolationKey", "background:#4fff4B", isolationKey); await memory.add("user", text); const [skill, mem] = await Promise.all([useSkill("script_agent_decision.md"), memory.get(text)]); @@ -59,7 +58,6 @@ export async function decisionAI(ctx: AgentContext) { ].join("\n"); const prefixSystem = `${projectInfo}\n\n## 章节ID映射表\n${novelData.map((i: any) => `- ${i.id}: 第${i.index}章`).join("\n")}\n\n`; - console.log("%c Line:57 🍧 prefixSystem", "background:#ea7e5c", prefixSystem); const { textStream } = await u.Ai.Text("scriptAgent").stream({ system: prefixSystem + systemPrompt, diff --git a/src/router.ts b/src/router.ts index 9556805..fad8e8b 100644 --- a/src/router.ts +++ b/src/router.ts @@ -1,4 +1,4 @@ -// @routes-hash fd1b3ec2552be041f1b6e9582eb842b6 +// @routes-hash adf6a50cb14a1d93aea2983d0364e6a3 import { Express } from "express"; import route1 from "./routes/agents/clearMemory"; @@ -38,7 +38,7 @@ import route34 from "./routes/novel/getNovelEventState"; import route35 from "./routes/novel/getNovelIndex"; import route36 from "./routes/novel/updateNovel"; import route37 from "./routes/other/deleteAllData"; -import route38 from "./routes/other/getCaptcha"; +import route38 from "./routes/other/getVersion"; import route39 from "./routes/production/assets/getAssetsData"; import route40 from "./routes/production/editImage/generateFlowImage"; import route41 from "./routes/production/editImage/getImageFlow"; @@ -135,7 +135,7 @@ export default async (app: Express) => { app.use("/api/novel/getNovelIndex", route35); app.use("/api/novel/updateNovel", route36); app.use("/api/other/deleteAllData", route37); - app.use("/api/other/getCaptcha", route38); + app.use("/api/other/getVersion", route38); app.use("/api/production/assets/getAssetsData", route39); app.use("/api/production/editImage/generateFlowImage", route40); app.use("/api/production/editImage/getImageFlow", route41); diff --git a/src/routes/other/getCaptcha.ts b/src/routes/other/getCaptcha.ts deleted file mode 100644 index 5b5eab4..0000000 --- a/src/routes/other/getCaptcha.ts +++ /dev/null @@ -1,13 +0,0 @@ -import express from "express"; -import { success } from "@/lib/responseFormat"; -import { md5 } from "js-md5"; -const router = express.Router(); - -// 获取验证码 -export default router.get("/", async (req, res) => { - const data: any = { svg: "", captcha: md5("123") }; - if (req.app.get("env") === "dev") { - data.key = 2; - } - res.status(200).send(success(data)); -}); diff --git a/src/routes/other/getVersion.ts b/src/routes/other/getVersion.ts new file mode 100644 index 0000000..0f53d52 --- /dev/null +++ b/src/routes/other/getVersion.ts @@ -0,0 +1,22 @@ +import express from "express"; +import { success } from "@/lib/responseFormat"; +const router = express.Router(); + +import fs from "fs"; +import path from "path"; + +declare const __APP_VERSION__: string | undefined; + +const APP_VERSION: string = (() => { + if (typeof __APP_VERSION__ !== "undefined") { + return __APP_VERSION__; + } + // 开发环境回退:从 package.json 读取 + const pkgPath = path.resolve(process.cwd(), "package.json"); + const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf8")); + return pkg.version; +})(); + +export default router.get("/", async (req, res) => { + res.status(200).send(success(APP_VERSION)); +});