A Remote magpie's editor has a new switch, Use its skills and prompts. The remote serves its Library at GET /v1/magpie/library (local or shared callers; a held key is refused; no MCP servers, which the MCP switch already covers; borrowed items are never passed on). The client fetches it every 10 minutes and once on switching on, and adds each skill and prompt set as remote-<id>-<name>, recording a hash of what it wrote. It only changes what still matches that hash: a skill or set of the user's by the same name, one the user edited, and one the user removed stay as they are; an update or drop moves the old copy to the backups; switching off takes out what is unchanged. The first set becomes active only when no prompt is active. Run (wsl-run, magpie-wt/remote-library at the pushed head after rebase): - go vet -tags nogui ./..., GOOS=windows and GOOS=darwin vet of library, provider, gateway, gui: clean. gofmt -l clean. - go test ./internal/library ./internal/provider: ok. internal/gateway: TestReadOnlyKeyEveryRoute named the new route (fixed here, now ok); the package then ran to the end of a 30m wsl timeout on a slow box. - TestBorrowRemoteLibrary and TestBorrowedSkillGoesWithTheRemote: broke by hand (the user's-own-skill guard turned off), TestBorrowRemoteLibrary went red with "kept []", restored. - GUI remote-magpie.test.cjs (chromium + webkit): its new assertions for the switch pass, but the file is red on main before this change (#6099: line 160 and a layout assertion), so they ran in a copy with those two assertions relaxed. i18n tests ran in the same call. Reds not mine: #6099, #6103 (TestSettingsSaveKeepsWhatItDoesNotSend). Not tried: a real two-machine run; internal/gui and gateway full packages to completion on wsl; Collect/Put (sync backups) still carry borrowed items as ordinary ones.
42 lines
1.4 KiB
Go
42 lines
1.4 KiB
Go
package provider
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
"net/http"
|
|
"time"
|
|
)
|
|
|
|
// RemoteLibraryPath is where a remote magpie tells its Library's prompts
|
|
// and skills (KoiLx0 on X: managed on one computer, not on every client).
|
|
// It is answered to the computer itself and to a full-access gateway key
|
|
// of a magpie shared on the local network, as the quotas are.
|
|
const RemoteLibraryPath = "/v1/magpie/library"
|
|
|
|
// RemoteLibraryWait is how long a remote magpie has to send its skills.
|
|
const RemoteLibraryWait = 90 * time.Second
|
|
|
|
// maxRemoteLibrary is the most a remote's Library answer is read to: its
|
|
// skills' files, base64 in JSON (library.Shared keeps them under 24 MiB).
|
|
const maxRemoteLibrary = 48 << 20
|
|
|
|
const errRemoteNoLibrary = "remote magpie doesn't share its Library; update magpie on that computer"
|
|
|
|
// RemoteLibrary is the body of the Library the remote magpie id shares,
|
|
// and the remote's name.
|
|
func RemoteLibrary(ctx context.Context, id string) ([]byte, string, error) {
|
|
p, err := Find(id)
|
|
if err != nil {
|
|
return nil, "", err
|
|
}
|
|
if !p.IsRemoteMagpie() {
|
|
return nil, "", fmt.Errorf("%s is no remote magpie", id)
|
|
}
|
|
if p.Key == "" || p.Anthropic == "" {
|
|
return nil, "", errors.New("the remote magpie's address and key are needed")
|
|
}
|
|
b, err := remoteBodyAs(ctx, *p, http.MethodGet, RemoteLibraryPath, RemoteLibraryWait, maxRemoteLibrary, errRemoteNoLibrary)
|
|
return b, remoteName(*p), err
|
|
}
|