🤖 Open-source, local-first alternative to Grok Bot, OpenAI dots and Claude Duet. Your own AI bots on any model: GPT, Claude, Gemini, Grok, DeepSeek, Kimi, GLM and 70+ more through one Modelflare key. Reach them in the app, WeChat or Feishu; they remember you, work in the background, run commands and use your computer. Pay per use.
Python ai-agentai-assistantchatbotclaudecomputer-usedeepseekdesktop-appdshelectronfeishugeminigptgrokllmlocal-firstmodelflaremulti-modelopenai-compatiblepersonal-ai-agentwechat
pack dsh runtime into dsh.asar and bump to 0.1.1
Marlaf22e17549449
diff --git a/dsh-runtime/package.json b/dsh-runtime/package.jsonindex 7455d45..4c0d07e 100644--- a/dsh-runtime/package.json+++ b/dsh-runtime/package.json@@ -1,11 +1,12 @@{"name": "anymodel-bot-dsh-runtime","private": true,- "description": "Pinned DeepSeek Harness (MIT) runtime used by anymodel bot as its agent host. Installed separately so it can ship outside the app asar.",+ "description": "Pinned DeepSeek Harness (MIT) runtime used by anymodel bot as its agent host. Packaged as resources/dsh.asar (natives in dsh.asar.unpacked).","type": "module","license": "MIT","dependencies": {"@deepseek-ai/dsh": "0.2.1-rc.4","@deepseek-ai/dsh-sdk-client": "0.2.1-rc.4"- }+ },+ "version": "0.1.1"}diff --git a/package.json b/package.jsonindex b77843d..357170e 100644--- a/package.json+++ b/package.json@@ -1,9 +1,9 @@{"name": "anymodel-bot","productName": "anymodel bot",- "version": "0.1.0",+ "version": "0.1.1","private": true,- "description": "anymodel bot:任意模型的个人 AI 助手(飞书 + 微信 iLink),内置 magpie 模型网关",+ "description": "anymodel bot\uff1a\u4efb\u610f\u6a21\u578b\u7684\u4e2a\u4eba AI \u52a9\u624b\uff08\u98de\u4e66 + \u5fae\u4fe1 iLink\uff09\uff0c\u5185\u7f6e magpie \u6a21\u578b\u7f51\u5173","license": "MIT","type": "module","main": "dist/electron/main.js",@@ -21,13 +21,14 @@"typecheck": "tsc -p tsconfig.json --noEmit","test": "vitest run","electron:dev": "npm run build && electron .",- "dist": "npm run build && node scripts/prepare-dsh.mjs && node scripts/build-magpie.mjs --target current && node scripts/fetch-cua-driver.mjs --target current && electron-builder",+ "dist": "npm run build && node scripts/prepare-dsh.mjs && node scripts/pack-dsh-asar.mjs && node scripts/build-magpie.mjs --target current && node scripts/fetch-cua-driver.mjs --target current && electron-builder","electron:smoke": "npm run build && node scripts/electron-smoke.mjs",- "dist:linux": "npm run build && node scripts/prepare-dsh.mjs && node scripts/build-magpie.mjs --target linux/amd64,linux/arm64 && node scripts/fetch-cua-driver.mjs --target linux/x64,linux/arm64 && electron-builder --linux",- "dist:mac": "npm run build && node scripts/prepare-dsh.mjs && node scripts/build-magpie.mjs --target darwin/amd64,darwin/arm64 && node scripts/fetch-cua-driver.mjs --target darwin/x64,darwin/arm64 && electron-builder --mac",- "dist:win": "npm run build && node scripts/prepare-dsh.mjs && node scripts/build-magpie.mjs --target windows/amd64,windows/arm64 && node scripts/fetch-cua-driver.mjs --target win32/x64,win32/arm64 && electron-builder --win",+ "dist:linux": "npm run build && node scripts/prepare-dsh.mjs && node scripts/pack-dsh-asar.mjs && node scripts/build-magpie.mjs --target linux/amd64,linux/arm64 && node scripts/fetch-cua-driver.mjs --target linux/x64,linux/arm64 && electron-builder --linux",+ "dist:mac": "npm run build && node scripts/prepare-dsh.mjs && node scripts/pack-dsh-asar.mjs && node scripts/build-magpie.mjs --target darwin/amd64,darwin/arm64 && node scripts/fetch-cua-driver.mjs --target darwin/x64,darwin/arm64 && electron-builder --mac",+ "dist:win": "npm run build && node scripts/prepare-dsh.mjs && node scripts/pack-dsh-asar.mjs && node scripts/build-magpie.mjs --target windows/amd64,windows/arm64 && node scripts/fetch-cua-driver.mjs --target win32/x64,win32/arm64 && electron-builder --win","prepare:dsh": "node scripts/prepare-dsh.mjs",- "fetch:cua": "node scripts/fetch-cua-driver.mjs"+ "fetch:cua": "node scripts/fetch-cua-driver.mjs",+ "pack:dsh": "node scripts/pack-dsh-asar.mjs"},"dependencies": {"@larksuiteoapi/node-sdk": "1.76.0",@@ -65,7 +66,11 @@"!**/*.map","LICENSE","THIRD_PARTY_NOTICES.md",- "LICENSES/**"+ "LICENSES/**",+ "!dist/*-unpacked{,/**}",+ "!dist/win-unpacked{,/**}",+ "!dist/mac{,/**}",+ "!dist/linux*-unpacked{,/**}"],"asar": true,"mac": {@@ -94,20 +99,11 @@"to": "magpie/magpie"},{- "from": "dsh-runtime",- "to": "dsh",+ "from": "build/dsh-pack",+ "to": ".","filter": [- "package.json",- "plugins/**"- ]- },- {- "from": "dsh-runtime/node_modules",- "to": "dsh/node_modules",- "filter": [- "**/*",- "!**/*.map",- "!**/*.d.ts"+ "dsh.asar",+ "dsh.asar.unpacked/**"]},{@@ -151,20 +147,11 @@"to": "magpie/magpie.exe"},{- "from": "dsh-runtime",- "to": "dsh",+ "from": "build/dsh-pack",+ "to": ".","filter": [- "package.json",- "plugins/**"- ]- },- {- "from": "dsh-runtime/node_modules",- "to": "dsh/node_modules",- "filter": [- "**/*",- "!**/*.map",- "!**/*.d.ts"+ "dsh.asar",+ "dsh.asar.unpacked/**"]},{@@ -206,20 +193,11 @@"to": "magpie/magpie"},{- "from": "dsh-runtime",- "to": "dsh",- "filter": [- "package.json",- "plugins/**"- ]- },- {- "from": "dsh-runtime/node_modules",- "to": "dsh/node_modules",+ "from": "build/dsh-pack",+ "to": ".","filter": [- "**/*",- "!**/*.map",- "!**/*.d.ts"+ "dsh.asar",+ "dsh.asar.unpacked/**"]},{diff --git a/scripts/pack-dsh-asar.mjs b/scripts/pack-dsh-asar.mjsnew file mode 100644index 0000000..1007e5c--- /dev/null+++ b/scripts/pack-dsh-asar.mjs@@ -0,0 +1,74 @@+#!/usr/bin/env node+/**+ * Pack dsh-runtime into build/dsh.asar (+ dsh.asar.unpacked for natives).+ * Shipped via electron-builder extraResources so we avoid app FileSet+ * excluding the FileSet-root node_modules directory.+ */+import fs from "node:fs";+import path from "node:path";+import { fileURLToPath } from "node:url";+import asar from "@electron/asar";++const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");+const src = path.join(root, "dsh-runtime");+const outDir = path.join(root, "build");+const dest = path.join(outDir, "dsh.asar");+const destUnpacked = path.join(outDir, "dsh.asar.unpacked");++if (!fs.existsSync(path.join(src, "node_modules", "@deepseek-ai", "dsh-sdk-client", "package.json"))) {+ console.error("dsh-runtime not prepared — run scripts/prepare-dsh.mjs first");+ process.exit(1);+}++fs.mkdirSync(outDir, { recursive: true });+fs.rmSync(dest, { force: true });+fs.rmSync(destUnpacked, { recursive: true, force: true });++const unpack =+ "{**/*.{node,dll,exe,dylib,so},**/prebuilds/**,**/sharp-*/**,**/libvips*,**/conpty/**,@img/**,@koromix/**,sherpa-onnx-*/**,@vscode/ripgrep-*/**,@deepseek-ai/libreoffice-kit-*/**}";++console.log("packing dsh-runtime → build/dsh.asar …");+await asar.createPackageWithOptions(src, dest, { unpack });++const asarSize = fs.statSync(dest).size;+let unpackedSize = 0;+if (fs.existsSync(destUnpacked)) {+ const walk = (d) => {+ for (const e of fs.readdirSync(d, { withFileTypes: true })) {+ const p = path.join(d, e.name);+ if (e.isDirectory()) walk(p);+ else unpackedSize += fs.statSync(p).size;+ }+ };+ walk(destUnpacked);+}++// Sanity: sdk-client must be inside the asar (or unpacked)+const list = asar.listPackage(dest);+const hasSdk = list.some((f) => f.replace(/\\/g, "/").includes("node_modules/@deepseek-ai/dsh-sdk-client/package.json"));+const hasDsh = list.some((f) => f.replace(/\\/g, "/").includes("node_modules/@deepseek-ai/dsh/package.json"));+if (!hasSdk || !hasDsh) {+ console.error("asar missing @deepseek-ai/dsh or dsh-sdk-client", { hasSdk, hasDsh, sample: list.slice(0, 20) });+ process.exit(1);+}++// Stage for electron-builder extraResources (avoids FileSet root node_modules filter)+const packDir = path.join(outDir, "dsh-pack");+fs.rmSync(packDir, { recursive: true, force: true });+fs.mkdirSync(packDir, { recursive: true });+fs.renameSync(dest, path.join(packDir, "dsh.asar"));+if (fs.existsSync(destUnpacked)) {+ fs.renameSync(destUnpacked, path.join(packDir, "dsh.asar.unpacked"));+}+// Keep stable paths build/dsh.asar for convenience+fs.linkSync(path.join(packDir, "dsh.asar"), dest);+if (fs.existsSync(path.join(packDir, "dsh.asar.unpacked"))) {+ // hardlink tree not practical; leave only under dsh-pack + recreate symlink+ try { fs.symlinkSync(path.join(packDir, "dsh.asar.unpacked"), destUnpacked, "dir"); } catch { /* ok */ }+}++console.log(+ `dsh.asar ready: ${(asarSize / 1048576).toFixed(1)} MB asar` ++ (unpackedSize ? ` + ${(unpackedSize / 1048576).toFixed(1)} MB unpacked` : "") ++ ` (${list.length} entries) → build/dsh-pack/`,+);diff --git a/scripts/prepare-dsh.mjs b/scripts/prepare-dsh.mjsindex f9ba313..d01629a 100644--- a/scripts/prepare-dsh.mjs+++ b/scripts/prepare-dsh.mjs@@ -49,6 +49,33 @@ if (fs.existsSync(koffi)) for (const pkg of fs.readdirSync(koffi)) {walk(nm, (p, name) => {if (/\.(map|d\.ts|d\.mts|d\.cts|tsbuildinfo)$/.test(name)) rm(p);});+// 其他平台的 libreoffice-kit 预编译包(只留当前 os-cpu)+const loPrefix = "@deepseek-ai";+const loRoot = path.join(nm, loPrefix);+if (fs.existsSync(loRoot)) {+ const want = `libreoffice-kit-${os === "win32" ? "win32" : os}-${cpu}`;+ for (const pkg of fs.readdirSync(loRoot)) {+ if (pkg.startsWith("libreoffice-kit-") && pkg !== want) rm(path.join(loRoot, pkg));+ }+}+// 已有平台 sharp 时丢掉 wasm 兜底(安装包体积)+const img = path.join(nm, "@img");+if (fs.existsSync(img)) {+ const hasNative = fs.readdirSync(img).some((d) => d.startsWith(`sharp-${os === "win32" ? "win32" : os}-`));+ if (hasNative) rm(path.join(img, "sharp-wasm32"));+}+// node-pty third_party 里非目标 arch 的 conpty+const ptyConpty = path.join(nm, "node-pty", "third_party", "conpty");+if (fs.existsSync(ptyConpty)) {+ for (const ver of fs.readdirSync(ptyConpty)) {+ const vdir = path.join(ptyConpty, ver);+ if (!fs.statSync(vdir).isDirectory()) continue;+ for (const archDir of fs.readdirSync(vdir)) {+ const keepArch = os === "win32" && ((cpu === "x64" && archDir === "win10-x64") || (cpu === "arm64" && archDir === "win10-arm64"));+ if (!keepArch) rm(path.join(vdir, archDir));+ }+ }+}console.log(`dsh-runtime 已准备(${keep}),裁剪 ${(removed / 1048576).toFixed(1)} MB`);function findDirs(base, name, out = []) {diff --git a/src/agent/host.ts b/src/agent/host.tsindex bd4d051..0de2743 100644--- a/src/agent/host.ts+++ b/src/agent/host.ts@@ -12,7 +12,7 @@ import { DEFAULT_SETTINGS, permissionMode, type BotSettings } from "./settings.jconst log = logger("agent.host");-// ---------- @deepseek-ai/dsh-sdk-client 的最小本地类型(运行时动态加载,避免进入 app asar) ----------+// ---------- @deepseek-ai/dsh-sdk-client 的最小本地类型(运行时从 dsh-runtime / app.asar/dsh 动态加载) ----------interface SdkNotification {method: string;params: any;@@ -38,14 +38,68 @@ interface SdkModule {DeepSeekHarness: new (opts: Record<string, unknown>) => SdkHarness;}-/** 找到随应用分发的 DSH 运行时目录(含 node_modules/@deepseek-ai/dsh)。 */+/** DSH 运行时是否具备可加载的 sdk-client。 */+function isDshRuntime(dir: string): boolean {+ return fs.existsSync(path.join(dir, "node_modules", "@deepseek-ai", "dsh-sdk-client", "package.json"));+}++/**+ * 找到随应用分发的 DSH 运行时目录(含 node_modules/@deepseek-ai/dsh)。+ * 打包后优先 `resources/dsh.asar`(extraResources);开发时用 `dsh-runtime/`。+ * `ELECTRON_RUN_AS_NODE` 子进程读不了 asar,调用方应再经 {@link materializeDshRuntime} 落到实目录。+ */export function locateDshRuntime(appRoot: string): string | undefined {+ const res = (process as any).resourcesPath as string | undefined;const cands = [process.env.AMB_DSH_RUNTIME,- (process as any).resourcesPath ? path.join((process as any).resourcesPath, "dsh") : undefined,- path.join(appRoot, "dsh-runtime"),+ path.join(appRoot, "dsh-runtime"), // dev checkout+ res ? path.join(res, "dsh.asar") : undefined, // packaged: resources/dsh.asar (+ .unpacked)+ res ? path.join(res, "dsh") : undefined, // legacy unpacked extraResources+ path.join(appRoot, "dsh"), // packaged inside app.asar (older layout)+ res ? path.join(res, "app.asar", "dsh") : undefined,+ res ? path.join(res, "app.asar.unpacked", "dsh") : undefined,].filter(Boolean) as string[];- return cands.find((d) => fs.existsSync(path.join(d, "node_modules", "@deepseek-ai", "dsh-sdk-client", "package.json")));+ return cands.find(isDshRuntime);+}++/**+ * 若运行时在 asar 内,复制到 cacheRoot/dsh-runtime/<version>,供 ELECTRON_RUN_AS_NODE 子进程使用。+ * Electron 主进程的 fs 能读 asar;复制时 asarUnpack 的原生模块也会落到实文件。+ */+export function materializeDshRuntime(runtimeDir: string, cacheRoot: string): string {+ if (!runtimeDir.split(path.sep).some((p) => p.endsWith(".asar"))) return runtimeDir;+ let version = "unknown";+ try {+ version = JSON.parse(fs.readFileSync(path.join(runtimeDir, "package.json"), "utf8")).version ?? version;+ } catch {+ try {+ version = JSON.parse(fs.readFileSync(path.join(runtimeDir, "node_modules", "@deepseek-ai", "dsh", "package.json"), "utf8")).version ?? version;+ } catch {+ /* keep unknown */+ }+ }+ // Prefer app version so cache invalidates on each anymodel bump even if dsh pin is unchanged.+ try {+ const appPj = path.join(runtimeDir, "..", "package.json");+ if (fs.existsSync(appPj)) {+ const v = JSON.parse(fs.readFileSync(appPj, "utf8")).version;+ if (v) version = v;+ }+ } catch {+ /* ignore */+ }+ const dest = path.join(cacheRoot, "dsh-runtime", version);+ const marker = path.join(dest, ".amb-dsh-ready");+ if (isDshRuntime(dest) && fs.existsSync(marker)) return dest;+ const tmp = `${dest}.tmp-${process.pid}`;+ fs.rmSync(tmp, { recursive: true, force: true });+ fs.mkdirSync(path.dirname(dest), { recursive: true });+ log.info("materializing dsh runtime from asar", { from: runtimeDir, to: dest });+ fs.cpSync(runtimeDir, tmp, { recursive: true });+ fs.writeFileSync(path.join(tmp, ".amb-dsh-ready"), new Date().toISOString());+ fs.rmSync(dest, { recursive: true, force: true });+ fs.renameSync(tmp, dest);+ return dest;}/** present 工具参数里的文件路径(原样,相对路径以工作区为准)。 */diff --git a/src/app.ts b/src/app.tsindex 28b4ffc..d5110d4 100644--- a/src/app.ts+++ b/src/app.ts@@ -13,7 +13,7 @@ import { WeixinLogin } from "./channels/weixin/login.js";import { startWebServer, type WebServer } from "./web/server.js";import { logger, mask } from "./log.js";import { AgentManager } from "./agent/manager.js";-import { locateDshRuntime } from "./agent/host.js";+import { locateDshRuntime, materializeDshRuntime } from "./agent/host.js";import { findAppRoot } from "./magpie/supervisor.js";const log = logger("app");@@ -69,7 +69,13 @@ export class App {this.agent = new AgentManager({store: this.store,dataDir: config.dataDir,- runtimeDir: config.agent.mode === "dsh" ? locateDshRuntime(findAppRoot()) : undefined,+ runtimeDir:+ config.agent.mode === "dsh"+ ? (() => {+ const located = locateDshRuntime(findAppRoot());+ return located ? materializeDshRuntime(located, config.dataDir) : undefined;+ })()+ : undefined,upstream,enabled: config.agent.mode === "dsh" && !opts.models,turnTimeoutMs: config.agent.turnTimeoutMs,