Adds @magpie-community/agent-deepzora: Deepzora on magpie's Agents page, through a reversible bridge that adds a magpie-agent provider to ~/.deepzora/config.toml and the key to ~/.deepzora/.env, and puts both back on disconnect. The package is reasonix-desktop's bridge with Deepzora's names; vendor.mjs is byte for byte the merged reasonix-desktop copy (sha256 46e08060…). Run at the reviewed head 858f09aa, on a separate test Mac, Bun 1.4.2 and Node 22.22.0, temp HOME: - bun test packages/deepzora: 12 pass; node --test: 12 pass - bun scripts/check.mjs: ok; npm pack --dry-run: 13 files, 57.0 kB - a probe over the bridge in temp dirs (corrupt and half-written TOML, user edits across a switch and a disconnect, pre-existing keys in four forms, CRLF, read-only dir, 0-byte config): each as expected - full root bun test at 858f09aa: 8482 pass, 20 skip, 0 fail Broken by hand: 17 breaks, 13 red. Four stay green (an edited credential on switch, a half-written control file read as disconnect, no provider_access cleanup, no lock), the same gaps reasonix-desktop's tests have; listed in the review. Not tried: a real Deepzora binary or session, acceptance.mjs and resident-acceptance.mjs, Windows (Deepzora uses %APPDATA%\deepzora there; the descriptor has no per-OS paths), a Deepzora Desktop settings save while connected. The first npm publish of @magpie-community/agent-deepzora is the maintainer's. Co-authored-by: SivanCola <SivanCola@users.noreply.github.com>
97 lines
5.5 KiB
JavaScript
97 lines
5.5 KiB
JavaScript
// Optional native acceptance. Everything uses disposable homes and a localhost
|
|
// model fixture: no user config, subscription credentials or paid model calls.
|
|
import assert from "node:assert/strict"
|
|
import fs from "node:fs"
|
|
import os from "node:os"
|
|
import path from "node:path"
|
|
import http from "node:http"
|
|
import { execFile } from "node:child_process"
|
|
import { promisify } from "node:util"
|
|
import { fileURLToPath } from "node:url"
|
|
import { parseTOML as parse, parseEnv } from "./vendor.mjs"
|
|
|
|
const exec = promisify(execFile)
|
|
const root = fs.mkdtempSync(path.join(os.tmpdir(), "magpie-deepzora-native-"))
|
|
const repo = fileURLToPath(new URL(".", import.meta.url))
|
|
const magpie = process.env.MAGPIE_BIN || "magpie"
|
|
const deepzora = process.env.DEEPZORA_BIN
|
|
const env = { ...process.env, HOME: root, USERPROFILE: root, XDG_CONFIG_HOME: path.join(root, ".config"), XDG_CACHE_HOME: path.join(root, ".cache"), XDG_STATE_HOME: path.join(root, ".state"), DEEPZORA_HOME: path.join(root, ".deepzora"), DEEPZORA_STATE_HOME: path.join(root, ".deepzora-state"), MAGPIE_NO_ACCOUNTS: "1" }
|
|
const dz = env.DEEPZORA_HOME
|
|
const config = path.join(dz, "config.toml")
|
|
const control = path.join(dz, "magpie-agent.json")
|
|
const run = async (bin, args) => exec(bin, args, { cwd: root, env, timeout: 120000, maxBuffer: 2 << 20 })
|
|
let requests = 0
|
|
let expectedKey = ""
|
|
const server = http.createServer(async (req, res) => {
|
|
let raw = ""
|
|
for await (const chunk of req) raw += chunk
|
|
if (req.method === "GET") {
|
|
res.setHeader("content-type", "application/json")
|
|
res.end(JSON.stringify({ object: "list", data: [{ id: "fixture/test-model", object: "model" }] }))
|
|
return
|
|
}
|
|
const body = JSON.parse(raw)
|
|
assert.equal(req.url, "/v1/chat/completions")
|
|
assert.equal(body.model, "fixture/test-model")
|
|
assert.equal(req.headers.authorization, `Bearer ${expectedKey}`)
|
|
requests++
|
|
if (body.stream) {
|
|
res.setHeader("content-type", "text/event-stream")
|
|
res.end(`data: ${JSON.stringify({ id: "fixture", object: "chat.completion.chunk", choices: [{ index: 0, delta: { role: "assistant", content: "bridge-ok" }, finish_reason: null }] })}\n\ndata: ${JSON.stringify({ id: "fixture", object: "chat.completion.chunk", choices: [{ index: 0, delta: {}, finish_reason: "stop" }] })}\n\ndata: [DONE]\n\n`)
|
|
} else {
|
|
res.setHeader("content-type", "application/json")
|
|
res.end(JSON.stringify({ id: "fixture", object: "chat.completion", choices: [{ index: 0, message: { role: "assistant", content: "bridge-ok" }, finish_reason: "stop" }], usage: { prompt_tokens: 10, completion_tokens: 2, total_tokens: 12 } }))
|
|
}
|
|
})
|
|
|
|
try {
|
|
await new Promise(resolve => server.listen(0, "127.0.0.1", resolve))
|
|
const base = `http://127.0.0.1:${server.address().port}/v1`
|
|
fs.mkdirSync(dz, { recursive: true })
|
|
fs.mkdirSync(path.join(env.XDG_CONFIG_HOME, "magpie"), { recursive: true })
|
|
const original = '# native acceptance fixture\ndefault_model="mine/model"\n[[providers]]\nname="mine"\nkind="openai"\nbase_url="http://127.0.0.1:49998/v1"\nmodels=["model"]\n'
|
|
fs.writeFileSync(config, original)
|
|
fs.writeFileSync(path.join(dz, ".env"), "OTHER_KEY=fixture-original\n")
|
|
fs.writeFileSync(path.join(env.XDG_CONFIG_HOME, "magpie/providers.json"), JSON.stringify({ providers: [{ id: "fixture", name: "Fixture", key: "fixture-only", chat: base, models: ["test-model"] }] }))
|
|
await run(magpie, ["plugin", "add", repo])
|
|
const agents = await run(magpie, ["agents"])
|
|
assert.match(agents.stdout, /Deepzora/)
|
|
await run(magpie, ["deepzora", "fixture/test-model"])
|
|
// Loading the real plugin host executes the companion bridge.
|
|
const loaded = await run(magpie, ["plugin", "list", "--json"])
|
|
assert.ok(!JSON.parse(loaded.stdout).loaded.some(plugin => plugin.error))
|
|
assert.equal(parse(fs.readFileSync(config, "utf8")).default_model, "magpie-agent/fixture/test-model")
|
|
console.log("PASS: Magpie installs and discovers the agent; its plugin host bridges the selected model")
|
|
if (deepzora) {
|
|
expectedKey = parseEnv(fs.readFileSync(path.join(dz, ".env"))).MAGPIE_DEEPZORA_API_KEY
|
|
assert.ok(expectedKey)
|
|
// Keep Magpie's selected ID and assigned key. Redirect only the isolated
|
|
// control file to a local API fixture so no live gateway account is used.
|
|
const cfg = JSON.parse(fs.readFileSync(control, "utf8"))
|
|
cfg.baseURL = base
|
|
fs.writeFileSync(control, JSON.stringify(cfg))
|
|
await run(process.execPath, [path.join(repo, "cli.mjs"), "sync"])
|
|
const result = await run(deepzora, ["-p", "Reply with bridge-ok", "--output-format", "json"])
|
|
assert.ok(requests > 0)
|
|
assert.match(result.stdout, /bridge-ok/)
|
|
console.log("PASS: unchanged Deepzora sends its selected model and assigned credential to the local API")
|
|
}
|
|
await run(magpie, ["deepzora", "default"])
|
|
await run(process.execPath, [path.join(repo, "cli.mjs"), "sync"])
|
|
if (deepzora) {
|
|
// Deepzora may migrate its config on startup; keep those unrelated edits.
|
|
const restored = parse(fs.readFileSync(config, "utf8"))
|
|
assert.equal(restored.default_model, "mine/model")
|
|
assert.deepEqual(restored.providers.map(p => p.name), ["mine"])
|
|
assert.equal(restored.providers[0].base_url, "http://127.0.0.1:49998/v1")
|
|
} else {
|
|
assert.equal(fs.readFileSync(config, "utf8"), original)
|
|
}
|
|
assert.equal(fs.readFileSync(path.join(dz, ".env"), "utf8"), "OTHER_KEY=fixture-original\n")
|
|
console.log("PASS: disconnect restores selection and credentials, preserving unrelated Deepzora edits")
|
|
} finally {
|
|
server.closeAllConnections()
|
|
await new Promise(resolve => server.close(resolve))
|
|
fs.rmSync(root, { recursive: true, force: true })
|
|
}
|