doubao-work: find 豆包工作 (DoubaoWork.app), not 豆包 (#917)
binary() looked only for /Applications/Doubao.app (豆包,
com.bot.pc.doubao). The reporter has only 豆包工作 at
/Applications/DoubaoWork.app/Contents/MacOS/DoubaoWork
(com.work.pc.doubao), so sign-in always said the app was missing.
choose() now picks { app, binary, dataDir } from both apps, 豆包工作
first, in /Applications and ~/Applications on macOS and under
%LOCALAPPDATA% on Windows. A user already signed in to 豆包 through
the plugin (its profile exists) stays on 豆包 while it is installed, so
the update signs no one out. 豆包工作 keeps its profile, port and model
list in a doubaowork/ subfolder. DOUBAO_WORK_APP still names the binary.
The chat page check (owns, connect) accepts doubaowork://doubaowork-chat/chat
and chrome://doubaowork-chat/chat as well as 豆包's. The busy and
not-installed messages name the chosen app and its download page.
Run (mote, worktree at 6cb5dbe8 + this change; origin/main 1bdc4d4b only
adds an autoclaw change):
- bun test packages/doubao-work: 36 pass, 0 fail.
- bun scripts/check.mjs: exit 0, doubao-work ok.
- Live on this Mac with DoubaoWork 2.36.3 (copied out of the official
dmg) and a sandbox DOUBAO_WORK_HOME: choose picked 豆包工作, App.start
launched it, owns accepted it, the page reported
chrome://doubaowork-chat/chat, input present, signed out; the model
menu read 自动 / 豆包 2.1 Lite / 豆包 2.1 Pro; the new-task and 云电脑
steps ran on the real page. A second connect reused the running app.
- 豆包 2.35.8 with a temp profile: same chat page test ids.
Broken by hand (mote): choose searching only 豆包 made "a Mac with only
豆包工作 drives 豆包工作 (#917)" red; the old owns regex made "both apps'
chat pages are the plugin's" red (34 pass, 2 fail). The old code has no
choose/isChat and binary() returns Doubao.app, so the #917 test is red
on it.
Not tried: a signed-in request (no 豆包工作 account here). Windows: the
path %LOCALAPPDATA%\DoubaoWork\Application\app\DoubaoWork.exe comes from
DoubaoWork_installer_2.36.3.exe's config (install_dir_name DoubaoWork,
exe_file_name DoubaoWork.exe) and 豆包's layout; not installed on the
Windows box. Running 豆包工作 and 豆包 side by side.
Reported-by: sinoyster
This commit is contained in:
@@ -1,15 +1,23 @@
|
||||
# 豆包工作 (Doubao Work)
|
||||
|
||||
Doubao Work runs its agent loop in ByteDance's cloud and has no API, so
|
||||
there is no request to make on its behalf. This plugin uses the Doubao
|
||||
desktop app the way a person does instead, and gives what it reads back as
|
||||
an OpenAI chat completion:
|
||||
there is no request to make on its behalf. This plugin uses its desktop
|
||||
app, 豆包工作 (DoubaoWork), the way a person does instead, and gives what it
|
||||
reads back as an OpenAI chat completion. 豆包 (Doubao), whose 工作任务 are the
|
||||
same, works too:
|
||||
|
||||
1. It starts Doubao from a profile of its own (`~/Library/Application
|
||||
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.
|
||||
1. It starts the app from a profile of its own (under
|
||||
`~/Library/Application Support/magpie-doubao-work` on macOS,
|
||||
`%LOCALAPPDATA%\magpie-doubao-work` on Windows; 豆包工作's in
|
||||
`doubaowork` there), with Chrome DevTools on a local port. Your everyday
|
||||
profile is not touched; you sign in once in this second window.
|
||||
|
||||
The app is 豆包工作 when it is installed (`/Applications/DoubaoWork.app` or
|
||||
`~/Applications/DoubaoWork.app` on macOS,
|
||||
`%LOCALAPPDATA%\DoubaoWork\Application\app\DoubaoWork.exe` on Windows),
|
||||
else 豆包 (`Doubao.app`, `%LOCALAPPDATA%\Doubao\Application\app\Doubao.exe`).
|
||||
If you signed in to 豆包 through the plugin before 0.1.5, it stays on 豆包
|
||||
while 豆包 is installed.
|
||||
2. Each request opens a new 工作任务, switches it from 本地电脑 to 云电脑
|
||||
(so Doubao's agent never reads or runs anything on your computer), picks
|
||||
the model, and writes the whole request (system prompt, tools, every
|
||||
@@ -36,7 +44,7 @@ fallback for when the menu cannot be read.
|
||||
|
||||
- **Unofficial.** It uses Doubao the way its own window does, but ByteDance
|
||||
may not like it. Use an account you can afford to lose.
|
||||
- **On macOS, Doubao runs one copy at a time.** If you opened Doubao
|
||||
- **On macOS, the app runs one copy at a time.** If you opened it
|
||||
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
|
||||
@@ -52,13 +60,12 @@ fallback for when the menu cannot be read.
|
||||
- **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 and Windows. Doubao has no Linux app.
|
||||
- macOS and Windows. Neither app has a Linux build.
|
||||
|
||||
## Settings
|
||||
|
||||
- `DOUBAO_WORK_APP`: the Doubao binary, if it is not at
|
||||
`/Applications/Doubao.app/Contents/MacOS/Doubao` (macOS) or
|
||||
`%LOCALAPPDATA%\Doubao\Application\app\Doubao.exe` (Windows).
|
||||
- `DOUBAO_WORK_APP`: the app's binary, if it is not in one of the places
|
||||
above. A path naming DoubaoWork is driven as 豆包工作, any other as 豆包.
|
||||
- `DOUBAO_WORK_HOME`: where the profile and port live.
|
||||
|
||||
## Adding another cloud agent
|
||||
|
||||
@@ -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, MENU, READ, STATE, MODELS, idFor, tableFrom, binary, dataDir, owns, usageOf } from "./doubao.mjs"
|
||||
import { Doubao, NEW_TASK, CLOUD, MENU, READ, STATE, MODELS, idFor, tableFrom, binary, choose, dataDir, owns, isChat, 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"
|
||||
@@ -154,28 +154,74 @@ test("on Windows a running copy of the app never blocks: Chromium keeps one copy
|
||||
}
|
||||
})
|
||||
|
||||
test("the app is found on macOS and Windows, or where DOUBAO_WORK_APP says", () => {
|
||||
// withEnv runs fn with the variables the app lookup reads unset.
|
||||
const withEnv = (fn) => {
|
||||
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("")
|
||||
// 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")
|
||||
return fn()
|
||||
} finally {
|
||||
for (const k of keys) {
|
||||
if (was[k] === undefined) delete process.env[k]
|
||||
else process.env[k] = was[k]
|
||||
}
|
||||
}
|
||||
}
|
||||
const only = (...paths) => (p) => paths.includes(p)
|
||||
|
||||
test("the app is found on macOS and Windows, or where DOUBAO_WORK_APP says", () =>
|
||||
withEnv(() => {
|
||||
// nothing installed: 豆包工作's own place, so the error names it
|
||||
expect(binary("darwin", "/Users/u", only())).toBe("/Applications/DoubaoWork.app/Contents/MacOS/DoubaoWork")
|
||||
// neither app has a Linux build
|
||||
expect(binary("linux", "/home/u", () => true)).toBe("")
|
||||
// Windows: the per-user install's own exe, not Application\<name>.exe's launcher
|
||||
expect(binary("win32", "C:\\Users\\u", only())).toBe("C:\\Users\\u\\AppData\\Local\\DoubaoWork\\Application\\app\\DoubaoWork.exe")
|
||||
const old = "C:\\Users\\u\\AppData\\Local\\Doubao\\Application\\app\\Doubao.exe"
|
||||
expect(binary("win32", "C:\\Users\\u", only(old))).toBe(old)
|
||||
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", only())).toBe("D:\\Local\\DoubaoWork\\Application\\app\\DoubaoWork.exe")
|
||||
expect(choose("win32", "C:\\Users\\u", only()).dataDir).toBe("D:\\Local\\magpie-doubao-work\\doubaowork")
|
||||
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")
|
||||
expect(choose("darwin", "/Users/u").app.name).toBe("豆包")
|
||||
process.env.DOUBAO_WORK_APP = "/opt/DoubaoWork.app/Contents/MacOS/DoubaoWork"
|
||||
expect(choose("darwin", "/Users/u").app.name).toBe("豆包工作")
|
||||
}))
|
||||
|
||||
// #917 (sinoyster): only 豆包工作 at its own path, no Doubao.app
|
||||
test("a Mac with only 豆包工作 drives 豆包工作 (#917)", () =>
|
||||
withEnv(() => {
|
||||
const work = "/Applications/DoubaoWork.app/Contents/MacOS/DoubaoWork"
|
||||
const c = choose("darwin", "/Users/u", only(work))
|
||||
expect(c.binary).toBe(work)
|
||||
expect(c.app.name).toBe("豆包工作")
|
||||
// its own profile, port and model list, apart from 豆包's
|
||||
expect(c.dataDir).toBe("/Users/u/Library/Application Support/magpie-doubao-work/doubaowork")
|
||||
// ~/Applications too
|
||||
const mine = "/Users/u/Applications/DoubaoWork.app/Contents/MacOS/DoubaoWork"
|
||||
expect(binary("darwin", "/Users/u", only(mine))).toBe(mine)
|
||||
// with both installed, 豆包工作 is the one, until someone signed in to 豆包 through the plugin
|
||||
const old = "/Applications/Doubao.app/Contents/MacOS/Doubao"
|
||||
expect(binary("darwin", "/Users/u", only(work, old))).toBe(work)
|
||||
expect(binary("darwin", "/Users/u", only(old))).toBe(old)
|
||||
const signedIn = "/Users/u/Library/Application Support/magpie-doubao-work/profile"
|
||||
const c2 = choose("darwin", "/Users/u", only(work, old, signedIn))
|
||||
expect(c2.binary).toBe(old)
|
||||
expect(c2.dataDir).toBe("/Users/u/Library/Application Support/magpie-doubao-work")
|
||||
// a 豆包 profile with 豆包 gone: 豆包工作
|
||||
expect(binary("darwin", "/Users/u", only(work, signedIn))).toBe(work)
|
||||
}))
|
||||
|
||||
test("both apps' chat pages are the plugin's", () => {
|
||||
// 豆包工作 2.36.3's DevTools list, from the real app
|
||||
expect(owns([{ url: "doubaowork://doubaowork-login/login?forceLogin=1" }, { url: "doubaowork://doubaowork-chat/chat" }])).toBe(true)
|
||||
expect(owns([{ url: "doubaowork://doubaowork-launcher/chat?viewId=101" }, { url: "doubaowork://doubaowork-background/" }])).toBe(false)
|
||||
expect(isChat("chrome://doubaowork-chat/chat")).toBe(true)
|
||||
expect(isChat("https://doubaowork-chat/chat")).toBe(false)
|
||||
})
|
||||
|
||||
test("owns knows Doubao's chat page", () => {
|
||||
@@ -484,17 +530,19 @@ test("the plugin passes a sign-out on for re-sign-in and other failures as HTTP
|
||||
})
|
||||
|
||||
test("sign-in waits for the Doubao window's account", async () => {
|
||||
const mac = () => "/Applications/Doubao.app/Contents/MacOS/Doubao"
|
||||
const ok = I.createPlugin({ appBinary: mac, doubao: { waitSignedIn: async () => ({ signedIn: true, name: "yetone" }) } })
|
||||
const mac = () => ({ app: { name: "豆包工作", download: "https://www.doubao.com/work" }, binary: "/Applications/DoubaoWork.app/Contents/MacOS/DoubaoWork" })
|
||||
const ok = I.createPlugin({ pick: mac, doubao: { waitSignedIn: async () => ({ signedIn: true, name: "yetone" }) } })
|
||||
const r = await (await ok.auth.methods[0].authorize()).callback()
|
||||
expect(r).toMatchObject({ type: "success", accountId: "豆包工作 · yetone" })
|
||||
const late = I.createPlugin({ appBinary: mac, doubao: { waitSignedIn: async () => null } })
|
||||
const late = I.createPlugin({ pick: mac, doubao: { waitSignedIn: async () => null } })
|
||||
expect(await (await late.auth.methods[0].authorize()).callback()).toMatchObject({ type: "failed", error: expect.stringContaining("五分钟") })
|
||||
const busy = I.createPlugin({ appBinary: mac, doubao: { waitSignedIn: async () => { throw Object.assign(Error("busy"), { code: "app_busy" }) } } })
|
||||
const busy = I.createPlugin({ pick: mac, doubao: { waitSignedIn: async () => { throw Object.assign(Error("busy"), { code: "app_busy" }) } } })
|
||||
const b = await (await busy.auth.methods[0].authorize()).callback()
|
||||
expect(b.type).toBe("failed")
|
||||
expect(b.error).toContain("退出豆包")
|
||||
const linux = I.createPlugin({ appBinary: () => "", doubao: { waitSignedIn: async () => ({ signedIn: true, name: "x" }) } })
|
||||
expect(b.error).toContain("退出豆包工作")
|
||||
const gone = I.createPlugin({ pick: mac, doubao: { waitSignedIn: async () => { throw Object.assign(Error("gone"), { code: "app_missing" }) } } })
|
||||
expect(await (await gone.auth.methods[0].authorize()).callback()).toMatchObject({ type: "failed", error: "没有找到豆包工作,请先安装:https://www.doubao.com/work" })
|
||||
const linux = I.createPlugin({ pick: () => ({ app: { name: "豆包工作" }, binary: "" }), doubao: { waitSignedIn: async () => ({ signedIn: true, name: "x" }) } })
|
||||
expect(await (await linux.auth.methods[0].authorize()).callback()).toMatchObject({ type: "failed", error: expect.stringContaining("没有 Linux 版") })
|
||||
})
|
||||
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
// The Doubao adapter: what the generic driver (cdp.mjs) does in Doubao's
|
||||
// desktop app (com.bot.pc.doubao, a Chromium fork) to run one request as
|
||||
// one new 工作任务 and read its reply.
|
||||
// The Doubao adapter: what the generic driver (cdp.mjs) does in 豆包工作
|
||||
// (DoubaoWork, com.work.pc.doubao) or 豆包 (Doubao, com.bot.pc.doubao) to
|
||||
// run one request as one new 工作任务 and read its reply. Both are the same
|
||||
// Chromium 147 fork serving the same chat page under their own scheme
|
||||
// (doubaowork://doubaowork-chat/chat, doubao://doubao-chat/chat), with the
|
||||
// same 新工作任务 button, mode and model menus.
|
||||
//
|
||||
// The reply is read from the React props of the reply's node, the message
|
||||
// object Doubao itself renders from: its text blocks are the raw markdown
|
||||
@@ -12,7 +15,9 @@ import os from "node:os"
|
||||
import path from "node:path"
|
||||
import { App, Page, sleep } from "./cdp.mjs"
|
||||
|
||||
export const CHAT = "doubao-chat/chat"
|
||||
// isChat says whether a page is either app's chat page. The page reports
|
||||
// itself as chrome://doubao(work)-chat/chat from inside.
|
||||
export const isChat = (url) => /^(doubao|doubaowork|chrome):\/\/(doubao|doubaowork)-chat\/chat/.test(String(url))
|
||||
|
||||
// Doubao has no API to ask which models it offers: the app's own model menu
|
||||
// is the list, and it changes as Doubao adds models. These are the ones the
|
||||
@@ -68,24 +73,64 @@ export function tableFrom(rows) {
|
||||
// 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 ""
|
||||
// APPS are the desktop apps the plugin drives, 豆包工作 first: it is the
|
||||
// app this plugin is named for. 豆包 has the same 工作任务 and was the only
|
||||
// one the plugin knew until 0.1.5 (#917). On Windows the exe is the one
|
||||
// under app\: Application\<name>.exe beside it is a launcher. Neither has
|
||||
// a Linux build (their download pages offer macOS and Windows).
|
||||
// sub the folder under dataDir() for this app's profile, port and model
|
||||
// list; 豆包's stays at the top, where 0.1.0 to 0.1.4 kept it
|
||||
export const APPS = [
|
||||
{ name: "豆包工作", mac: "DoubaoWork.app/Contents/MacOS/DoubaoWork", win: ["DoubaoWork", "Application", "app", "DoubaoWork.exe"], sub: "doubaowork", download: "https://www.doubao.com/work" },
|
||||
{ name: "豆包", mac: "Doubao.app/Contents/MacOS/Doubao", win: ["Doubao", "Application", "app", "Doubao.exe"], sub: "", download: "https://www.doubao.com/download/desktop" },
|
||||
]
|
||||
|
||||
// places lists where an app can be installed: /Applications, then
|
||||
// ~/Applications on macOS; %LOCALAPPDATA% on Windows.
|
||||
export function places(app, platform = process.platform, home = os.homedir()) {
|
||||
if (platform === "darwin") return [path.posix.join("/Applications", app.mac), path.posix.join(home, "Applications", app.mac)]
|
||||
if (platform === "win32") return [path.win32.join(localAppData(home), ...app.win)]
|
||||
return []
|
||||
}
|
||||
|
||||
// choose picks the app to drive: { app, binary, dataDir }. DOUBAO_WORK_APP
|
||||
// names the binary outright. A user already signed in to 豆包 through this
|
||||
// plugin (its profile exists) stays on 豆包 while it is installed, so an
|
||||
// update never signs them out. Otherwise the first app installed, 豆包工作
|
||||
// first; with neither, 豆包工作's own place, so the error names it. On
|
||||
// Linux the binary is "".
|
||||
export function choose(platform = process.platform, home = os.homedir(), exists = fs.existsSync) {
|
||||
const P = platform === "win32" ? path.win32 : path.posix
|
||||
const base = dataDir(platform, home)
|
||||
const out = (app, bin) => ({ app, binary: bin, dataDir: app.sub ? P.join(base, app.sub) : base })
|
||||
const [work, doubao] = APPS
|
||||
if (process.env.DOUBAO_WORK_APP) {
|
||||
const bin = process.env.DOUBAO_WORK_APP
|
||||
return out(/doubaowork/i.test(bin) ? work : doubao, bin)
|
||||
}
|
||||
const found = (app) => places(app, platform, home).find((p) => exists(p))
|
||||
const old = found(doubao)
|
||||
if (old && exists(P.join(base, "profile"))) return out(doubao, old)
|
||||
for (const app of APPS) {
|
||||
const bin = found(app)
|
||||
if (bin) return out(app, bin)
|
||||
}
|
||||
return out(work, places(work, platform, home)[0] ?? "")
|
||||
}
|
||||
|
||||
// binary is the executable choose picks.
|
||||
export function binary(platform = process.platform, home = os.homedir(), exists = fs.existsSync) {
|
||||
return choose(platform, home, exists).binary
|
||||
}
|
||||
|
||||
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 === "darwin") return path.posix.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")
|
||||
}
|
||||
|
||||
export const owns = (list) => list.some((t) => String(t.url).includes(CHAT) && /^(doubao|chrome):/.test(String(t.url)))
|
||||
export const owns = (list) => list.some((t) => isChat(t.url))
|
||||
|
||||
// Page-side helpers, run through Runtime.evaluate. They read the page and
|
||||
// press its controls the way a pointer does (Radix menus open on
|
||||
@@ -231,7 +276,11 @@ export class DoubaoError extends Error {
|
||||
// Doubao drives the app. One request runs at a time: there is one window.
|
||||
export class Doubao {
|
||||
constructor({ app, openPage = Page.open, poll = 150, idle = 180000, total = 900000, fresh = 6 * 60 * 60 * 1000 } = {}) {
|
||||
this.app = app ?? new App({ binary: binary(), dataDir: dataDir(), owns })
|
||||
if (!app) {
|
||||
const c = choose()
|
||||
app = new App({ binary: c.binary, dataDir: c.dataDir, owns })
|
||||
}
|
||||
this.app = app
|
||||
Object.assign(this, { openPage, poll, idle, total, fresh })
|
||||
this.cacheFile = this.app?.dataDir ? path.join(this.app.dataDir, "models.json") : ""
|
||||
this.table = null
|
||||
@@ -295,7 +344,7 @@ export class Doubao {
|
||||
async connect(signal) {
|
||||
if (this.page && !this.page.closed) return this.page
|
||||
const port = await this.app.start({ signal })
|
||||
this.page = await this.openPage(port, (t) => String(t.url).includes(CHAT))
|
||||
this.page = await this.openPage(port, (t) => isChat(t.url))
|
||||
if (!this.page) throw new DoubaoError("豆包的对话窗口没有打开。请在豆包里打开一个对话窗口后再试。", "doubao_no_window")
|
||||
return this.page
|
||||
}
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
// 豆包工作 (Doubao Work) as a model provider. Doubao Work runs its agent
|
||||
// loop in ByteDance's cloud and has no API, so this plugin uses the app
|
||||
// the way a person does: it opens Doubao's desktop app from a profile of
|
||||
// the way a person does: it opens 豆包工作 (or 豆包) from a profile of
|
||||
// its own, starts a new 工作任务 per request on 云电脑, writes the whole
|
||||
// request into the input, and reads the reply as Doubao renders it. The
|
||||
// client's tools are asked for as <tool_call> text blocks and given back
|
||||
// as OpenAI tool_calls. See README.md for what that costs.
|
||||
import { Doubao, DoubaoError, MODELS, binary, usageOf } from "./doubao.mjs"
|
||||
import { Doubao, DoubaoError, MODELS, choose, usageOf } from "./doubao.mjs"
|
||||
import { completion, sse } from "./openai.mjs"
|
||||
import { flatten } from "./prompt.mjs"
|
||||
|
||||
const ID = "doubao-work"
|
||||
const BASE = "https://doubao-work.invalid/v1"
|
||||
|
||||
const BUSY = "豆包正在运行。豆包同时只能开一个,插件要用自己的豆包窗口:请先退出豆包(⌘Q)再试。"
|
||||
const BUSY = (name) => `${name}正在运行。${name}同时只能开一个,插件要用自己的${name}窗口:请先退出${name}(⌘Q)再试。`
|
||||
|
||||
const json = (status, message, type) =>
|
||||
new Response(JSON.stringify({ error: { message, type } }), { status, headers: { "Content-Type": "application/json" } })
|
||||
@@ -38,12 +38,14 @@ function models(table = MODELS) {
|
||||
// it (never opening the app here), or the built-in fallback.
|
||||
const modelTable = (doubao) => (typeof doubao?.modelList === "function" ? doubao.modelList() : MODELS)
|
||||
|
||||
export function createPlugin({ doubao = new Doubao(), newId, appBinary = binary } = {}) {
|
||||
// pick says which app the plugin drives (doubao.mjs choose): its name goes
|
||||
// in the messages, and no binary at all means Linux.
|
||||
export function createPlugin({ doubao = new Doubao(), newId, pick = choose } = {}) {
|
||||
const failed = (e) => {
|
||||
if (e?.signIn) throw e
|
||||
if (e?.name === "AbortError" || e?.name === "TimeoutError") throw e
|
||||
const status = String(e?.code ?? "").startsWith("app_") ? 503 : e?.status ?? 502
|
||||
return json(status, e?.code === "app_busy" ? BUSY : String(e?.message ?? e), e?.code ?? "doubao_error")
|
||||
return json(status, e?.code === "app_busy" ? BUSY(pick().app.name) : String(e?.message ?? e), e?.code ?? "doubao_error")
|
||||
}
|
||||
return {
|
||||
config: async (cfg) => {
|
||||
@@ -72,15 +74,16 @@ export function createPlugin({ doubao = new Doubao(), newId, appBinary = binary
|
||||
authorize: async () => ({
|
||||
url: "",
|
||||
method: "auto",
|
||||
instructions: "将打开一个单独的豆包窗口(不影响你平时用的豆包)。请在其中登录,登录后回到这里。",
|
||||
instructions: "将打开一个单独的豆包工作窗口(不影响你平时用的豆包工作或豆包)。请在其中登录,登录后回到这里。",
|
||||
callback: async () => {
|
||||
if (!appBinary()) return { type: "failed", error: "豆包工作插件只支持 macOS 和 Windows 上的豆包桌面版:豆包没有 Linux 版。" }
|
||||
const { app, binary } = pick()
|
||||
if (!binary) return { type: "failed", error: "豆包工作插件只支持 macOS 和 Windows:豆包工作和豆包都没有 Linux 版。" }
|
||||
let s
|
||||
try {
|
||||
s = await doubao.waitSignedIn()
|
||||
} catch (e) {
|
||||
if (e?.code === "app_missing") return { type: "failed", error: "没有找到豆包桌面版,请先安装:https://www.doubao.com/download/desktop" }
|
||||
if (e?.code === "app_busy") return { type: "failed", error: BUSY }
|
||||
if (e?.code === "app_missing") return { type: "failed", error: `没有找到${app.name},请先安装:${app.download}` }
|
||||
if (e?.code === "app_busy") return { type: "failed", error: BUSY(app.name) }
|
||||
return { type: "failed", error: "打开豆包失败:" + String(e?.message ?? e) }
|
||||
}
|
||||
if (!s) return { type: "failed", error: "五分钟内没有在豆包窗口里登录,请再试一次。" }
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@magpie-community/opencode-doubao-work-auth",
|
||||
"version": "0.1.4",
|
||||
"version": "0.1.5",
|
||||
"type": "module",
|
||||
"main": "./opencode.mjs",
|
||||
"files": [
|
||||
@@ -13,7 +13,7 @@
|
||||
"opencode2.mjs",
|
||||
"README.md"
|
||||
],
|
||||
"description": "Doubao Work (豆包工作) as a model provider, by driving the Doubao desktop app the way a person does",
|
||||
"description": "Doubao Work (豆包工作) as a model provider, by driving the 豆包工作 (or 豆包) desktop app the way a person does",
|
||||
"magpie": {
|
||||
"maxConcurrency": 1
|
||||
},
|
||||
|
||||
+1
-1
@@ -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 and Windows; unofficial.", "zh": "豆包工作的智能体跑在云端、没有 API,本插件像人一样操作豆包桌面版来用它:每个请求开一个新任务,客户端的工具以文本方式调用。macOS 和 Windows;非官方。"}},
|
||||
{"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 its desktop app (or Doubao's) 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 免费模型,自动发现模型并支持原生流式协议。" } },
|
||||
|
||||
Reference in New Issue
Block a user