diff --git a/README.md b/README.md index afe2c84..25fb97a 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ subscription and makes its requests. The packages work in OpenCode and in | [grok](packages/grok) | Grok (SuperGrok / X Premium+), through the Grok Build CLI's sign-in | `grok` | | [inkstone](packages/inkstone) | (Unofficial) 书生·端砚 Token Plan: browser sign-in gives the ink-credit balance, the 5-hour and 7-day windows and the credit packs, and creates an `ink-*` API key to serve the plan's models for chat | `intern-inkstone` | | [joycode](packages/joycode) | JoyCode IDE credits with JD account browser sign-in, live models and credit multipliers (unofficial) | `joycode` | -| [doubao-work](packages/doubao-work) | Doubao Work (豆包工作), whose agent runs in the cloud with no API, through the Doubao desktop app driven the way a person uses it (macOS) | `doubao-work` | +| [doubao-work](packages/doubao-work) | Doubao Work (豆包工作), whose agent runs in the cloud with no API, through the Doubao desktop app driven the way a person uses it (macOS, Windows) | `doubao-work` | | [kimi-work](packages/kimi-work) | Ordinary Kimi desktop Work subscription, through the desktop app's local sign-in; separate from Kimi Code | `kimi-work` | | [kiro](packages/kiro) | Kiro (Free, Pro, Pro+, Power), with Kiro's sign-in, kiro-cli's or the IDE's, or an API key | `kiro` | | [loomy](packages/loomy) | iFlytek's Loomy (loomyad.xunfei.cn), with SMS sign-in | `loomy` | diff --git a/packages/doubao-work/README.md b/packages/doubao-work/README.md index 8ae065b..7765e5f 100644 --- a/packages/doubao-work/README.md +++ b/packages/doubao-work/README.md @@ -6,8 +6,9 @@ desktop app the way a person does instead, and gives what it reads back as an OpenAI chat completion: 1. It starts Doubao from a profile of its own (`~/Library/Application - Support/magpie-doubao-work/profile`), with Chrome DevTools on a local - port. Your everyday Doubao's profile is not touched; you sign in once + Support/magpie-doubao-work/profile` on macOS, + `%LOCALAPPDATA%\magpie-doubao-work\profile` on Windows), with Chrome + DevTools on a local port. Your everyday Doubao's profile is not touched; you sign in once in this second window. 2. Each request opens a new 工作任务, switches it from 本地电脑 to 云电脑 (so Doubao's agent never reads or runs anything on your computer), picks @@ -25,11 +26,12 @@ Models: 自动 (`auto`), 豆包 2.1 Lite (`doubao-2.1-lite`) and 豆包 2.1 Pro - **Unofficial.** It uses Doubao the way its own window does, but ByteDance may not like it. Use an account you can afford to lose. -- **Doubao runs one copy at a time.** If you opened Doubao yourself, - quit it (⌘Q) first: the plugin's copy can't start beside it, and yours - can't be driven (Chromium allows debugging only off the default - profile). While the plugin's copy runs, opening Doubao brings up its - window, which you can use as well. +- **On macOS, Doubao runs one copy at a time.** If you opened Doubao + yourself, quit it (⌘Q) first: the plugin's copy can't start beside it, + and yours can't be driven (Chromium allows debugging only off the + default profile). While the plugin's copy runs, opening Doubao brings up + its window, which you can use as well. On Windows the plugin's copy runs + beside yours, in a second window. - **One request at a time.** There is one window. - **Every request is a new task** in your Doubao history. - **A request the client stops** stops being read, but Doubao finishes @@ -40,12 +42,13 @@ Models: 自动 (`auto`), 豆包 2.1 Lite (`doubao-2.1-lite`) and 豆包 2.1 Pro - **Usage** is Doubao's own prompt count; the reply's tokens are estimated. - **The DevTools port** is on 127.0.0.1 only, but any program on this computer can drive the signed-in Doubao window through it while it runs. -- macOS only for now. +- macOS and Windows. Doubao has no Linux app. ## Settings - `DOUBAO_WORK_APP`: the Doubao binary, if it is not at - `/Applications/Doubao.app/Contents/MacOS/Doubao`. + `/Applications/Doubao.app/Contents/MacOS/Doubao` (macOS) or + `%LOCALAPPDATA%\Doubao\Application\app\Doubao.exe` (Windows). - `DOUBAO_WORK_HOME`: where the profile and port live. ## Adding another cloud agent diff --git a/packages/doubao-work/cdp.mjs b/packages/doubao-work/cdp.mjs index 454b9e2..9e40860 100644 --- a/packages/doubao-work/cdp.mjs +++ b/packages/doubao-work/cdp.mjs @@ -51,8 +51,11 @@ export async function targets(port, fetchImpl = fetch) { } // copies lists the command lines of the processes running binary itself -// (not its helpers), or none where ps can't tell (Windows). -export function copies(binary) { +// (not its helpers), or none where ps can't tell. On Windows it is none: +// there, Chromium keeps one copy per profile, not per app, so a copy the +// user opened doesn't keep this one from starting beside it. +export function copies(binary, platform = process.platform) { + if (platform === "win32") return [] let out = "" try { out = execFileSync("ps", ["-axww", "-o", "command="], { encoding: "utf8", stdio: ["ignore", "pipe", "ignore"] }) diff --git a/packages/doubao-work/doubao-work.test.mjs b/packages/doubao-work/doubao-work.test.mjs index 2ed971e..964b0b3 100644 --- a/packages/doubao-work/doubao-work.test.mjs +++ b/packages/doubao-work/doubao-work.test.mjs @@ -3,7 +3,7 @@ import fs from "node:fs" import os from "node:os" import path from "node:path" import { App, Page, copies } from "./cdp.mjs" -import { Doubao, NEW_TASK, CLOUD, READ, STATE, binary, owns, usageOf } from "./doubao.mjs" +import { Doubao, NEW_TASK, CLOUD, READ, STATE, binary, dataDir, owns, usageOf } from "./doubao.mjs" import { Streamer, sse, completion } from "./openai.mjs" import { flatten, parse, heldFrom } from "./prompt.mjs" import { _internal as I } from "./index.mjs" @@ -141,18 +141,40 @@ test("usageOf adds Doubao's prompt counts", () => { expect(usageOf("nope")).toBe(0) }) -test("the app is found on macOS only, or where DOUBAO_WORK_APP says", () => { - const was = process.env.DOUBAO_WORK_APP - delete process.env.DOUBAO_WORK_APP +test("on Windows a running copy of the app never blocks: Chromium keeps one copy per profile there", async () => { + if (process.platform === "win32") return expect(copies("C:\\x.exe")).toEqual([]) + const child = Bun.spawn(["/bin/sleep", "30"]) + try { + let seen = [] + for (let i = 0; i < 50 && !seen.length; i++) { seen = copies("/bin/sleep"); if (!seen.length) await Bun.sleep(20) } + expect(seen.length).toBeGreaterThan(0) + expect(copies("/bin/sleep", "win32")).toEqual([]) + } finally { + child.kill() + } +}) + +test("the app is found on macOS and Windows, or where DOUBAO_WORK_APP says", () => { + const keys = ["DOUBAO_WORK_APP", "DOUBAO_WORK_HOME", "LOCALAPPDATA"] + const was = Object.fromEntries(keys.map((k) => [k, process.env[k]])) + for (const k of keys) delete process.env[k] try { expect(binary("darwin")).toBe("/Applications/Doubao.app/Contents/MacOS/Doubao") + // Doubao has no Linux build expect(binary("linux")).toBe("") - expect(binary("win32")).toBe("") + // Windows: the per-user install's own exe, not Application\Doubao.exe's launcher + expect(binary("win32", "C:\\Users\\u")).toBe("C:\\Users\\u\\AppData\\Local\\Doubao\\Application\\app\\Doubao.exe") + expect(dataDir("win32", "C:\\Users\\u")).toBe("C:\\Users\\u\\AppData\\Local\\magpie-doubao-work") + process.env.LOCALAPPDATA = "D:\\Local" + expect(binary("win32", "C:\\Users\\u")).toBe("D:\\Local\\Doubao\\Application\\app\\Doubao.exe") + expect(dataDir("win32", "C:\\Users\\u")).toBe("D:\\Local\\magpie-doubao-work") process.env.DOUBAO_WORK_APP = "/opt/doubao" expect(binary("linux")).toBe("/opt/doubao") } finally { - if (was === undefined) delete process.env.DOUBAO_WORK_APP - else process.env.DOUBAO_WORK_APP = was + for (const k of keys) { + if (was[k] === undefined) delete process.env[k] + else process.env[k] = was[k] + } } }) @@ -291,6 +313,7 @@ test("App says at once that a copy the user opened keeps it from starting", asyn test("copies lists the binary's own processes only", () => { expect(copies("/no/such/binary-" + Date.now())).toEqual([]) + }) test("waitSignedIn says the app not starting at once, and waits for a window still loading", async () => { @@ -402,7 +425,7 @@ test("sign-in waits for the Doubao window's account", async () => { expect(b.type).toBe("failed") expect(b.error).toContain("退出豆包") const linux = I.createPlugin({ appBinary: () => "", doubao: { waitSignedIn: async () => ({ signedIn: true, name: "x" }) } }) - expect(await (await linux.auth.methods[0].authorize()).callback()).toMatchObject({ type: "failed", error: expect.stringContaining("macOS") }) + expect(await (await linux.auth.methods[0].authorize()).callback()).toMatchObject({ type: "failed", error: expect.stringContaining("没有 Linux 版") }) }) test("an abort between two polls stops the ask too", async () => { diff --git a/packages/doubao-work/doubao.mjs b/packages/doubao-work/doubao.mjs index 98bdc0f..26b6d18 100644 --- a/packages/doubao-work/doubao.mjs +++ b/packages/doubao-work/doubao.mjs @@ -18,15 +18,24 @@ export const MODELS = { "doubao-2.1-pro": { label: "豆包 2.1 Pro", name: "豆包 2.1 Pro" }, } -export function binary(platform = process.platform) { +// localAppData is %LOCALAPPDATA%, where Doubao's Windows installer puts +// the app for the user who installs it. +const localAppData = (home) => process.env.LOCALAPPDATA || path.win32.join(home, "AppData", "Local") + +// binary is Doubao's own executable. On Windows that is app\Doubao.exe: +// Application\Doubao.exe beside it is a launcher. Doubao has no Linux +// build (its download page offers macOS and Windows), so Linux has none. +export function binary(platform = process.platform, home = os.homedir()) { if (process.env.DOUBAO_WORK_APP) return process.env.DOUBAO_WORK_APP if (platform === "darwin") return "/Applications/Doubao.app/Contents/MacOS/Doubao" + if (platform === "win32") return path.win32.join(localAppData(home), "Doubao", "Application", "app", "Doubao.exe") return "" } export function dataDir(platform = process.platform, home = os.homedir()) { if (process.env.DOUBAO_WORK_HOME) return process.env.DOUBAO_WORK_HOME if (platform === "darwin") return path.join(home, "Library", "Application Support", "magpie-doubao-work") + if (platform === "win32") return path.win32.join(localAppData(home), "magpie-doubao-work") return path.join(process.env.XDG_DATA_HOME || path.join(home, ".local", "share"), "magpie-doubao-work") } diff --git a/packages/doubao-work/index.mjs b/packages/doubao-work/index.mjs index c9e86d8..df552f4 100644 --- a/packages/doubao-work/index.mjs +++ b/packages/doubao-work/index.mjs @@ -58,7 +58,7 @@ export function createPlugin({ doubao = new Doubao(), newId, appBinary = binary method: "auto", instructions: "将打开一个单独的豆包窗口(不影响你平时用的豆包)。请在其中登录,登录后回到这里。", callback: async () => { - if (!appBinary()) return { type: "failed", error: "豆包工作插件目前只支持 macOS 上的豆包桌面版。" } + if (!appBinary()) return { type: "failed", error: "豆包工作插件只支持 macOS 和 Windows 上的豆包桌面版:豆包没有 Linux 版。" } let s try { s = await doubao.waitSignedIn() diff --git a/packages/doubao-work/package.json b/packages/doubao-work/package.json index d0af075..3ca6936 100644 --- a/packages/doubao-work/package.json +++ b/packages/doubao-work/package.json @@ -1,6 +1,6 @@ { "name": "@magpie-community/opencode-doubao-work-auth", - "version": "0.1.2", + "version": "0.1.3", "type": "module", "main": "./opencode.mjs", "files": [ diff --git a/registry.json b/registry.json index 8b7c571..0be5516 100644 --- a/registry.json +++ b/registry.json @@ -25,7 +25,7 @@ "summary": { "en": "GitHub Copilot on GitHub.com or GitHub Enterprise, with premium request or credit usage, remaining allowance and quota reset dates.", "zh": "GitHub Copilot:支持 GitHub.com 与 GitHub Enterprise,显示高级请求或积分用量、剩余额度和重置时间。" } }, { "package": "@magpie-community/opencode-joycode-auth", "name": "JoyCode", "providers": ["joycode"], "community": true, "summary": { "en": "Unofficial JoyCode provider: JD account browser sign-in, live models and credit multipliers, plan credits and streaming tool calls.", "zh": "非官方 JoyCode 插件:京东账号浏览器登录,动态模型与积分倍率、套餐额度及流式工具调用。" } }, - {"package": "@magpie-community/opencode-doubao-work-auth", "name": "豆包工作", "icon": "doubao-color", "providers": ["doubao-work"], "community": true, "summary": {"en": "Doubao Work, which runs its agent in the cloud and has no API, used through the Doubao desktop app the way a person does: one new task per request, the client's tools asked for as text. macOS; unofficial.", "zh": "豆包工作的智能体跑在云端、没有 API,本插件像人一样操作豆包桌面版来用它:每个请求开一个新任务,客户端的工具以文本方式调用。仅 macOS;非官方。"}}, + {"package": "@magpie-community/opencode-doubao-work-auth", "name": "豆包工作", "icon": "doubao-color", "providers": ["doubao-work"], "community": true, "summary": {"en": "Doubao Work, which runs its agent in the cloud and has no API, used through the Doubao desktop app the way a person does: one new task per request, the client's tools asked for as text. macOS and Windows; unofficial.", "zh": "豆包工作的智能体跑在云端、没有 API,本插件像人一样操作豆包桌面版来用它:每个请求开一个新任务,客户端的工具以文本方式调用。macOS 和 Windows;非官方。"}}, {"package": "@magpie-community/opencode-kimi-work-auth", "name": "Kimi Work", "icon": "kimi", "providers": ["kimi-work"], "community": true, "summary": {"en": "Kimi desktop Work subscription through its local sign-in, with live Work models and shared membership usage. Separate from Kimi Code.", "zh": "使用本机普通 Kimi 桌面版的 Work 登录,自动读取 Work 模型和会员共享用量;独立于 Kimi Code。"}}, { "package": "@magpie-community/opencode-zen-free-auth", "name": "OpenCode Zen Free", "icon": "opencode", "providers": ["opencode-zen-free"], "community": true, "summary": { "en": "OpenCode Zen's free models with the public credential, automatic discovery and native streaming protocols.", "zh": "使用 public 凭证接入 OpenCode Zen 免费模型,自动发现模型并支持原生流式协议。" } },