registry: a package that declares magpie.agent is listed as an agent, with a main or without (#737)
An agent that needs a runtime (miaocell's magpie-agent-deva) keeps its moejs agent file and adds a Bun module as main, as agent-kimi-desktop and agent-reasonix-desktop do. The README's agent convention now says so, and that such a package is kind "agent" in registry.json. check.mjs fails a registry entry whose package declares magpie.agent but whose kind is not "agent" (agentKindProblems in scripts/registry.mjs). magpie's side is v0.1.2995 (ed7aeb052): the GitHub list and the Installed row read the declaration, not the main. Run: bun test scripts/check.test.mjs, 17 pass (the new test also checks the repo's real kimi-desktop, reasonix-desktop and aider packages); bun scripts/check.mjs exit 0. Broken by hand: agent-kimi-desktop's kind removed from registry.json made check.mjs fail with '@magpie-community/agent-kimi-desktop declares magpie.agent, but its entry's kind is null, not "agent"'; restored. No package version changes, so nothing publishes.
This commit is contained in:
@@ -264,10 +264,18 @@ magpie plugin add @magpie-community/agent-<name>
|
||||
|
||||
An agent package is a folder under `packages/<name>/` with:
|
||||
|
||||
- **`package.json`**: name `@magpie-community/agent-<name>`, `"magpie": {"agent": "./<name>.agent.js"}`, no `main`.
|
||||
- **`package.json`**: name `@magpie-community/agent-<name>`, `"magpie": {"agent": "./<name>.agent.js"}`, and no `main` unless the agent needs a runtime (below).
|
||||
- **`<name>.agent.js`**: exports `agent` (where the agent keeps its model) and, if it needs more than the model, `connect` (the other keys to write) ([the reference](https://usemagpie.ai/docs/plugins#agents)). It runs in magpie on moejs, so it is one file and imports nothing.
|
||||
- a test of what `connect` returns.
|
||||
|
||||
An agent that needs more than moejs gives it (a timer, a file watched, a
|
||||
value carried into the app's own config while it runs) keeps its
|
||||
`<name>.agent.js` as above and adds a Bun module as the package's `main`,
|
||||
run in the plugin host as a provider plugin's is (kimi-desktop and
|
||||
reasonix-desktop do). It is still an agent: magpie lists a package that
|
||||
declares `magpie.agent` under Agents, on GitHub too, `main` or not, and its
|
||||
Installed row wears Provider only when that module serves a provider.
|
||||
|
||||
## Skills
|
||||
|
||||
Agent skills for magpie users, in `skills/<name>/SKILL.md`.
|
||||
@@ -392,7 +400,8 @@ MIT
|
||||
`registry.json` is the list magpie's Plugins tab shows: the packages
|
||||
here. An entry that signs in to nothing has a `"kind"` and no `providers`:
|
||||
`"middleware"` for gateway middleware and routing strategies, `"tools"`,
|
||||
`"page"` or `"agent"`. magpie
|
||||
`"page"` or `"agent"`. A package that declares `magpie.agent` is
|
||||
`"agent"`, with a `main` or without. magpie
|
||||
fetches it every few hours and keeps a copy built into the app for when
|
||||
it can't. To list a plugin, add an entry with its npm `package`, a
|
||||
`name`, `providers` (the provider ids it signs in to), an `icon` (one
|
||||
|
||||
+4
-2
@@ -9,14 +9,16 @@
|
||||
import { readdirSync, readFileSync, existsSync } from "node:fs"
|
||||
import { join, resolve } from "node:path"
|
||||
import { pathToFileURL } from "node:url"
|
||||
import { registryProblems } from "./registry.mjs"
|
||||
import { agentKindProblems, registryProblems } from "./registry.mjs"
|
||||
|
||||
const root = resolve(import.meta.dir, "..", "packages")
|
||||
const only = process.argv[2]
|
||||
let failed = 0
|
||||
{
|
||||
const file = resolve(import.meta.dir, "..", "registry.json")
|
||||
const problems = existsSync(file) ? registryProblems(readFileSync(file, "utf8")) : ["registry.json is missing"]
|
||||
const source = existsSync(file) ? readFileSync(file, "utf8") : null
|
||||
const pkgs = readdirSync(root).map((n) => join(root, n, "package.json")).filter(existsSync).map((f) => JSON.parse(readFileSync(f, "utf8")))
|
||||
const problems = source === null ? ["registry.json is missing"] : [...registryProblems(source), ...agentKindProblems(source, pkgs)]
|
||||
if (problems.length) failed++
|
||||
console.log(problems.length ? `✗ registry.json\n ${problems.join("\n ")}` : "✓ registry.json")
|
||||
}
|
||||
|
||||
+16
-1
@@ -2,7 +2,7 @@ import { expect, test } from "bun:test"
|
||||
import { copyFileSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs"
|
||||
import { tmpdir } from "node:os"
|
||||
import { join } from "node:path"
|
||||
import { registryProblems } from "./registry.mjs"
|
||||
import { agentKindProblems, registryProblems } from "./registry.mjs"
|
||||
|
||||
// Exercise the checker in a tiny independent repository, without loading any
|
||||
// real plugin, credential file or network client.
|
||||
@@ -134,6 +134,21 @@ test("check passes this repository's own registry.json", () => {
|
||||
expect(registryProblems(readFileSync(new URL("../registry.json", import.meta.url), "utf8"))).toEqual([])
|
||||
})
|
||||
|
||||
// a package that adds an agent is listed as one, with a Bun module
|
||||
// (main) beside it or not (#737): kimi-desktop and reasonix-desktop have one
|
||||
test("an agent package's entry is kind agent, main or not (#737)", () => {
|
||||
const reg = (kind) => JSON.stringify({ version: 1, plugins: [{ package: "@magpie-community/agent-deva", name: "Deva", kind, summary: { en: "D", zh: "D" } }] })
|
||||
const pkg = { name: "@magpie-community/agent-deva", main: "./index.mjs", magpie: { agent: "./deva.agent.js" } }
|
||||
expect(agentKindProblems(reg("agent"), [pkg])).toEqual([])
|
||||
expect(agentKindProblems(reg(undefined), [pkg])[0]).toContain('declares magpie.agent, but its entry\'s kind is null')
|
||||
expect(agentKindProblems(reg("tools"), [pkg])).toHaveLength(1)
|
||||
expect(agentKindProblems(reg(undefined), [{ ...pkg, magpie: {} }])).toEqual([])
|
||||
const own = new URL("../packages/", import.meta.url)
|
||||
const pkgs = ["kimi-desktop", "reasonix-desktop", "aider"].map((n) => JSON.parse(readFileSync(new URL(n + "/package.json", own), "utf8")))
|
||||
expect(pkgs.filter((p) => p.main).length).toBe(2)
|
||||
expect(agentKindProblems(readFileSync(new URL("../registry.json", import.meta.url), "utf8"), pkgs)).toEqual([])
|
||||
})
|
||||
|
||||
test("check fails a registry.json that is not JSON (#612)", () => {
|
||||
const result = check(fine, okRegistry.slice(0, -2))
|
||||
expect(result.code).toBe(1)
|
||||
|
||||
@@ -57,3 +57,20 @@ export function registryProblems(source) {
|
||||
})
|
||||
return problems
|
||||
}
|
||||
|
||||
// The packages here whose package.json declares an agent (magpie.agent)
|
||||
// and whose entry isn't "kind": "agent": magpie lists a package that adds
|
||||
// an agent as an agent, a Bun module (main) beside it or not (#737), so its
|
||||
// entry says so too. pkgs is each package.json, parsed.
|
||||
export function agentKindProblems(source, pkgs) {
|
||||
let r
|
||||
try {
|
||||
r = JSON.parse(source)
|
||||
} catch {
|
||||
return []
|
||||
}
|
||||
const kindOf = new Map((Array.isArray(r?.plugins) ? r.plugins : []).map((e) => [e?.package, e?.kind]))
|
||||
return pkgs
|
||||
.filter((p) => typeof p?.magpie?.agent === "string" && p.magpie.agent.trim() && kindOf.has(p.name) && kindOf.get(p.name) !== "agent")
|
||||
.map((p) => `${p.name} declares magpie.agent, but its entry's kind is ${JSON.stringify(kindOf.get(p.name) ?? null)}, not "agent"`)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user