miaocell's magpie-agent-deva ships a Bun module as its main beside its moejs agent file (deva.agent.js), because the agent needs a runtime. The market's GitHub list decided the kind by whether a main was there, so it listed the package under Providers, and the Installed row wore a Provider chip and a provider logo though the module serves no provider. Now readTagged gives Kind "agent" to any package that declares magpie.agent; middleware, page and hooks still need no main to be that kind. The file looked for in the repository is still the module Bun loads (its main), or the agent file when there is no main. The Installed row of an agent plugin wears Provider only when its module serves a provider, and its logo is the agent glyph unless it does. The moejs descriptor contract is unchanged. The community registry.json already gives kimi-desktop and reasonix-desktop (both with a main) kind agent; the plugins repo's check now fails an agent package listed as any other kind. Docs: docs/reference.md, docs/subsystems/provider-plugins.md, and site/public/docs plugins.html in en, zh and ja say an agent that needs a runtime keeps its agent file and adds a Bun main, and is listed as an agent either way. Run (on mote, at this head rebased onb047cfe73): - TestTaggedAgentWithMain (new; the reporter's real package.json, index.mjs and deva.agent.js in testdata): go test -run 'Tagged|PkgEntry|Readme|GitHub' ./internal/plugin ok. Red with github.go at its parent: kind "". - plugin-agent.test.cjs (new rows: an agent with a main and no provider, one switched off, one that serves a provider), chromium and webkit, en, zh, zh-TW, ja, de: ok. Red at origin/mainb047cfe73: the deva row's chips were [Agent, Provider]. - Every plugin*.test.cjs plus i18n-keys, both engines: 1090 of 1094 ok. The 4 reds are plugin-move-unserved "Try again takes the models unticked" (Model 1 folded behind "Show the other 29"), red the same at origin/main b047cfe73; filed as #4410. - gofmt -l, go vet ./internal/plugin ./internal/gui, GOOS=linux and GOOS=windows go vet ./internal/plugin, go test -run 'Budget|I18n' ./internal/gui (TestCoreScriptBudget, budget not raised): ok. Not tried: installing magpie-agent-deva from the real GitHub list in a running app (the list is read from the test server); Windows and Linux runs of the GUI tests.
62 lines
2.2 KiB
Go
62 lines
2.2 KiB
Go
package plugin
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"os"
|
|
"path/filepath"
|
|
"slices"
|
|
"strings"
|
|
"sync"
|
|
"testing"
|
|
)
|
|
|
|
// An agent plugin whose agent needs a runtime (a poller, files watched)
|
|
// ships a Bun module as its main beside its moejs agent file. It loads
|
|
// and adds its agent, but the GitHub list read a package with a main as
|
|
// a provider and showed it under Providers (miaocell, plugins#737). A
|
|
// package that declares magpie.agent is an agent plugin, main or not;
|
|
// the file looked for in the repository is still the one Bun loads, its
|
|
// main. The package.json, module and agent file are
|
|
// miaocell/magpie-agent-deva's, as they are; it isn't on npm.
|
|
func TestTaggedAgentWithMain(t *testing.T) {
|
|
var mu sync.Mutex
|
|
var asked []string
|
|
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, q *http.Request) {
|
|
mu.Lock()
|
|
asked = append(asked, q.URL.Path)
|
|
mu.Unlock()
|
|
name, ok := strings.CutPrefix(q.URL.Path, "/raw/")
|
|
f, err := os.ReadFile(filepath.Join("testdata/github/raw", filepath.FromSlash(name)))
|
|
if !ok || err != nil {
|
|
http.Error(w, `"Not Found"`, 404)
|
|
return
|
|
}
|
|
w.Write(f)
|
|
}))
|
|
t.Cleanup(srv.Close)
|
|
api, raw, reg := githubAPI, githubRaw, npmRegistry
|
|
githubAPI, githubRaw, npmRegistry = srv.URL, srv.URL+"/raw", srv.URL+"/npm"
|
|
t.Cleanup(func() { githubAPI, githubRaw, npmRegistry = api, raw, reg })
|
|
|
|
const repo = "miaocell/magpie-agent-deva"
|
|
got, keep, known, err := readTagged(context.Background(), Tagged{Spec: "github:" + repo, Repo: repo}, "main")
|
|
if !keep || !known || err != nil || got.Kind != "agent" || got.Package != "magpie-agent-deva" || got.Spec != "github:"+repo {
|
|
t.Fatalf("an agent with a main: kind %q, package %q, spec %q, kept %v, known %v, %v", got.Kind, got.Package, got.Spec, keep, known, err)
|
|
}
|
|
mu.Lock()
|
|
a := slices.Clone(asked)
|
|
mu.Unlock()
|
|
if !slices.Contains(a, "/raw/"+repo+"/main/index.mjs") {
|
|
t.Fatalf("its main wasn't looked for: asked %v", a)
|
|
}
|
|
|
|
// an agent alone, no main, as before: its agent file is the one
|
|
// looked for
|
|
got, keep, _, err = readTagged(context.Background(), Tagged{Spec: "github:someone/agent-aider", Repo: "someone/agent-aider"}, "main")
|
|
if !keep || err != nil || got.Kind != "agent" {
|
|
t.Fatalf("an agent alone: %+v, kept %v, %v", got, keep, err)
|
|
}
|
|
}
|