Files
magpie/internal/gui/pluginpage.go
T
yetone 5eab14a8cc plugin pages: magpie web reaches a page's local service on its own address, so the chat page works from another computer
aigcfree (Discord DM) runs `magpie web --addr 0.0.0.0:3430` on an Ubuntu
server behind nginx and opens it from a Windows PC. Plugins -> 对话
(@magpie-community/page-chat) showed "127.0.0.1 refused to connect": the
page sends its frame to the chat server on 127.0.0.1, which in that
browser is the Windows PC.

A plugin now declares its page's service (package.json
magpie.page.service {port, option}: the port, or the plugin option that
holds it, from its plugins.json options; plugin.ServiceSpec). Served to a
browser (isWeb), /api/plugin-pages gives the page `service`:
_magpie/service/ under its token, and the bridge hands the frame
magpie.service as an absolute address. The desktop window and slot pages
get none, and the routes answer 404 there, so the local path is as before.

servePageService reverse-proxies /_magpie/plugin/<token>/_magpie/service/…
to 127.0.0.1:<port>. The service stays on loopback. The way in is the
page's own: the per-run token that only a signed-in /api hands out,
behind AllowGuard. Nothing is weakened:
- Host is set to 127.0.0.1:<port>, which the service's rebinding check
  wants.
- The window's cookie is taken off.
- Origin must be absent or null (403 otherwise).
- Set-Cookie is dropped.
- Every reply is sandboxed (sandbox allow-scripts; frame-ancestors
  'self'), with Referrer-Policy no-referrer and nosniff.
- The gateway's own port is never served, since a request from this
  server is loopback and the gateway takes that without a key.
- Event streams flush as they come (FlushInterval -1, X-Accel-Buffering:
  no for nginx). webCompressed no longer gzips text/event-stream, which
  held a stream back until gzip's buffer filled.
- A redirect to the service's own address is made relative.
- The entry starts the plugin host as the page's HTML does (pageHost).
- A service not up yet answers its frame with a 502 page that tries
  again in 2s.

page-chat 0.1.2 (magpie-community/plugins 4a46212, on dist) declares the
service, goes to magpie.service when given one (else 0.1.1's path:
127.0.0.1 on loopback, the SSH-tunnel note from elsewhere), and asks
api/… by relative address.

Docs: plugin-runtime.md P4 (the page row), gui-shell.md (no gzip for event
streams).

Tests: TestPluginPageServiceListedToBrowserOnly, TestPluginPageServiceSpec,
TestPluginPageServiceProxied (through webHandler: Host, cookie, Set-Cookie,
CSP, escaped path and query, foreign Origin 403, made-up token 404,
redirects, SSE first event before the end and not gzipped),
TestPluginPageServiceDown, TestServiceLocation; plugin-page.test.cjs
checks magpie.service in a browser page and its absence in a slot.

Run at 276683d85, this change on origin/main e61e10535. It was rebased
since onto c1660481c, a one-line WorkBuddy mover min in internal/provider.
181fd0a68
(another session's proxy, path _service/, {portOption}) is reverted
there by 3870ddf0a, and nothing of it is left:
- go test ./internal/gui/ ./internal/plugin/ -timeout 45m, native on the
  Windows box: every new test ok. 8 reds, none in code this touches:
  - 6 fail the same at origin/main c1660481c, run there by name:
    TestGatewayHeldByAContainer, TestLodyImportHandoff,
    TestImportStatusUnreadableIsUnknown, TestAionUiImportRow,
    TestUpdateThatWontStart, TestPiPackage. All are in #4115.
  - TestLoadConcurrentWithSavesAndEdits is red 2 of 3 alone here and red
    at c1660481c too (a rename "Access is denied"); it is in #1827.
  - TestDesktopSessionTitlesOnPages passes alone (3 of 3). In the package
    run it listed the box's real WSL Codex session. Filed as #4185.
- Earlier, at bc247a8cc, on mote: the new Go tests, and go vet of both
  packages.
- Not run at this tree: the full go test ./... . mote was at load 300+
  with three other sessions' full suites, and the Linux box had one. A
  run at an older base (fa5ff2fec) had 25 packages ok, internal/agent
  among them, and none red when it was stopped for the rebase.
- gofmt -l: clean. go vet ./internal/gui ./internal/plugin: darwin on
  mote, native Windows on xiaomi-gpu. A Linux vet from mote fails in wails'
  cgo files, and in WSL for lack of gtk4/webkitgtk-6.0 headers, both
  unrelated to this change; CI vets Linux with its headers.
- plugin-page.test.cjs on the Windows box, both engines: WebKit 3/3.
  Chromium's first test is #4180, which fails the same on origin/main
  f463a8aaf. The next commit fixes #4180 at its cause.
- Real: a sandbox magpie web on mote (0.0.0.0:3561, sandbox HOME,
  MAGPIE_WEB_KEY, the real chat package from a folder, a fake gateway).
  Playwright on the Windows box opened Plugins -> chat over the LAN in
  Chromium and WebKit. The frame went to
  http://mote.local:3561/_magpie/plugin/<tok>/_magpie/service/?theme=…
  with origin null. Its fonts.css and style.css came through the proxy. A
  sent message streamed back "remote chat works", and the fake gateway
  logged both POSTs.
  - From the Mac over the LAN: /api/plugin-pages without the cookie
    gives 401. A made-up token gives 404. A foreign Origin gives 403.
    POST api/chat without the chat token gives 403 (the service's own
    check). mote.local:3563 directly is refused (loopback only).
  - Before bun was reachable in the sandbox, the frame got the 502 retry
    page.
- Broken by hand, each red then restored:
  - Without the event-stream exclusion, the stream arrives gzipped.
  - Without the Host rewrite, the cookie strip or the web gate, each
    assertion is red.
  - With the bridge's service dropped, plugin-page.test.cjs is red in
    WebKit ("magpie.service").

Not tried:
- A real nginx in front.
- A WebSocket through the proxy (httputil handles the upgrade; the chat
  page uses none).
- TLS (--tls-cert).
- The desktop app with page-chat 0.1.2: its fallback is 0.1.1's path,
  covered by the plugin's launcher tests.
2026-10-29 14:28:24 +08:00

566 lines
18 KiB
Go

package gui
import (
"context"
"crypto/hmac"
"crypto/rand"
"crypto/sha256"
_ "embed"
"encoding/hex"
"encoding/json"
"errors"
"fmt"
"log"
"net/http"
"os"
"path/filepath"
"slices"
"strconv"
"strings"
"sync"
"time"
"github.com/yetone/magpie/internal/plugin"
"github.com/yetone/magpie/internal/provider"
"github.com/yetone/magpie/internal/usage"
)
// A community plugin's own page in magpie's window (P4 of
// docs/subsystems/plugin-runtime.md): package.json's magpie.page, shown in
// a sandboxed frame (pluginpages.js), and its panels in magpie's own pages
// (magpie.panels, P5), each in a frame of its own shut in the same way.
// Their files are served under
// pluginPagePrefix and a token only this run of magpie hands out, with a
// policy that lets the page load nothing but its own files and reach
// nothing over the network; it has no way to magpie's /api (apiFramed),
// and what it may read of magpie's it asks the window for, which asks
// /api/plugin-pages/read for the reads its package declared.
// pluginPagePrefix is where a plugin's page's files are served:
// pluginPagePrefix + token + "/" + the file's path in the page's folder.
const pluginPagePrefix = "/_magpie/plugin/"
// pluginBridgePath is the window's side of the page's messages, served
// beside every page's files: a page loads it as
// <script src="_magpie/bridge.js">.
const pluginBridgePath = "_magpie/bridge.js"
//go:embed pagebridge.js
var pageBridgeJS []byte
// pageSecret keys this run's tokens: a token from an earlier run, or one
// made up, serves nothing.
var pageSecret = func() []byte {
b := make([]byte, 32)
if _, err := rand.Read(b); err != nil {
panic(err)
}
return b
}()
func pageToken(spec string) string {
m := hmac.New(sha256.New, pageSecret)
m.Write([]byte(spec))
return hex.EncodeToString(m.Sum(nil)[:16])
}
// pluginPage is a plugin's page, of a plugin that is on.
type pluginPage struct {
Spec string `json:"spec"`
Name string `json:"name"` // its package's
Key string `json:"key"` // the window's page key
Title string `json:"title"` // the page's, or the package's short name
// Titles are its title by the window's language (plugin.PageSpec)
Titles map[string]string `json:"titles,omitempty"`
URL string `json:"url"` // the page, under pluginPagePrefix
Icon string `json:"icon,omitempty"`
// Replaces is the built-in page whose place it takes: the first
// plugin's in plugins.json's order to ask for it
Replaces string `json:"replaces,omitempty"`
Reads []string `json:"reads"` // what it may read, of plugin.PageReads
// Actions are its items in magpie's menus (plugin.ActionSpec); each
// opens this page
Actions []pluginAction `json:"actions,omitempty"`
// Service is where a browser reaches the page's local service
// (plugin.ServiceSpec) through this server, relative to the page's own
// address: only on a page served to a browser (servePageService)
Service string `json:"service,omitempty"`
token string
dir string
file string // its HTML, relative to dir, with forward slashes
hosted bool // its plugin has a part for the host too (pageHost)
service *plugin.ServiceSpec
options map[string]any // its plugin's, as plugins.json keeps them
}
// pluginAction is an item a plugin's page adds to one of magpie's menus.
type pluginAction struct {
ID string `json:"id"`
Menu string `json:"menu"` // of plugin.ActionMenus
Title string `json:"title"` // its own, or its page's
Titles map[string]string `json:"titles,omitempty"`
}
// pluginPanel is a panel a plugin that is on adds to one of magpie's own
// pages (plugin.PanelSlots).
type pluginPanel struct {
Spec string `json:"spec"`
Name string `json:"name"` // its package's
Key string `json:"key"` // the panel's, among every plugin's
Slot string `json:"slot"` // the page it is in
Title string `json:"title"` // the panel's, or the package's short name
Titles map[string]string `json:"titles,omitempty"`
URL string `json:"url"` // the panel, under pluginPagePrefix
Reads []string `json:"reads"` // what it may read, of plugin.PageReads
token string
dir string
file string
hosted bool
}
// pageKeyChars are what a window page's key can't have
var pageKeyChars = strings.NewReplacer("@", "", "/", "-", ".", "-", "_", "-", " ", "-")
// windowParts are the pages and the panels of the plugins that are on, in
// plugins.json's order. A plugin switched off has none: its files aren't
// served.
func windowParts() (pages []pluginPage, panels []pluginPanel) {
seen := map[string]bool{}
replaced := map[string]bool{}
for _, e := range plugin.Load().Plugins {
if e.Off {
continue
}
w, only := plugin.Window(plugin.Target(e.Spec))
if w == nil {
continue
}
name := plugin.PackageName(e.Spec)
key := "plugin-" + strings.Trim(pageKeyChars.Replace(strings.ToLower(plugin.ShortName(name))), "-")
key = strings.Map(func(r rune) rune {
if r >= 'a' && r <= 'z' || r >= '0' && r <= '9' || r == '-' {
return r
}
return -1
}, key)
for k, n := key, 2; seen[key]; n++ {
key = fmt.Sprintf("%s-%d", k, n)
}
seen[key] = true
reads := w.Reads
if reads == nil {
reads = []string{}
}
if spec := w.Page; spec != nil {
tok := pageToken(e.Spec)
rel, _ := filepath.Rel(spec.Dir, spec.File)
p := pluginPage{Spec: e.Spec, Name: name, Key: key, Title: spec.Title, Titles: spec.Titles, Reads: reads, token: tok, dir: spec.Dir,
URL: pluginPagePrefix + tok + "/" + filepath.ToSlash(rel), file: filepath.ToSlash(rel), hosted: !only, options: e.Options}
if !only {
p.service = spec.Service
}
if p.Title == "" {
p.Title = plugin.ShortName(name)
}
if spec.Icon != "" {
p.Icon = pluginPagePrefix + tok + "/" + spec.Icon
}
if r := spec.Replaces; r != "" && !replaced[r] {
replaced[r] = true
p.Replaces = r
}
for _, a := range w.Actions {
act := pluginAction{ID: a.ID, Menu: a.Menu, Title: a.Title, Titles: a.Titles}
// one that names no title is the page's own, in each language
if act.Title == "" {
act.Title, act.Titles = p.Title, p.Titles
}
p.Actions = append(p.Actions, act)
}
pages = append(pages, p)
}
for i, spec := range w.Panels {
tok := pageToken(e.Spec + "\x00panel\x00" + strconv.Itoa(i))
rel, _ := filepath.Rel(spec.Dir, spec.File)
p := pluginPanel{Spec: e.Spec, Name: name, Key: fmt.Sprintf("%s-%d", key, i), Slot: spec.Slot, Title: spec.Title, Titles: spec.Titles, Reads: reads,
token: tok, dir: spec.Dir, URL: pluginPagePrefix + tok + "/" + filepath.ToSlash(rel), file: filepath.ToSlash(rel), hosted: !only}
if p.Title == "" {
p.Title = plugin.ShortName(name)
}
panels = append(panels, p)
}
}
return pages, panels
}
// pluginPages are the pages of the plugins that are on.
func pluginPages() []pluginPage {
pages, _ := windowParts()
return pages
}
// windowOf is a plugin that is on and adds a page or a panel to the
// window: its package's name and the reads it declared.
func windowOf(spec string) (name string, reads []string, ok bool) {
pages, panels := windowParts()
for _, p := range pages {
if p.Spec == spec {
return p.Name, p.Reads, true
}
}
for _, p := range panels {
if p.Spec == spec {
return p.Name, p.Reads, true
}
}
return "", nil, false
}
// pagePolicy is what a plugin's page may load and reach: its own files,
// inline styles, data: pictures, and nothing over the network. sandbox
// keeps a page opened by itself (not in the window's frame) as shut in as
// the frame keeps it.
func pagePolicy(r *http.Request, tok string) string {
own := "'self'"
if r.Host != "" {
// the page's own folder: not the window's files, nor /api
own = r.Host + pluginPagePrefix + tok + "/"
// WebKit does not match a scheme-less host source under wails://.
// Only the native handler supplies this scheme; web keeps its
// relative source so HTTP, HTTPS and reverse proxies still work.
if scheme, _ := r.Context().Value(windowSchemeKey{}).(string); scheme != "" {
own = scheme + "://" + own
}
}
return strings.Join([]string{
"sandbox allow-scripts",
"default-src 'none'",
"script-src " + own,
"style-src " + own + " 'unsafe-inline'",
"img-src " + own + " data:",
"font-src " + own,
"media-src " + own,
"connect-src 'none'",
"frame-src 'none'",
"worker-src 'none'",
"object-src 'none'",
"form-action 'none'",
"base-uri 'none'",
"frame-ancestors 'self'",
}, "; ")
}
// pageHostWait is how long a page's HTML waits for its plugin's host,
// short of the window's 10 seconds for the page to say hello
// (pluginpages.js's HELLO_MS).
var pageHostWait = 7 * time.Second
// warmHost starts the plugin host if it isn't up; tests replace it.
var warmHost = plugin.Warm
// pageHost has the plugin host up for a page whose plugin has a part for
// it too, waiting pageHostWait at most. Such a page can be the way into
// a service that part runs: Magiczerowxy/magpie-chat's page sends its
// frame to the chat server its host part starts. The host starts only on
// a call, and every Restart (a plugin installed, updated or set, a Bun
// update) stops it until the next one, so with no other plugin asking,
// the page went to a server that wasn't there: Chromium shows its
// connection error, and WebKit (the Mac's and Linux's window) leaves the
// frame on the page's own "connecting…" for good. The host starts in the
// background under its own two minutes, as every caller's does, so a
// slow one isn't cut off when the page stops waiting.
func pageHost(ctx context.Context) {
done := make(chan struct{})
warm := warmHost // read here: the start can outlive the page's wait
go func() {
defer close(done)
c, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
defer cancel()
if err := warm(c); err != nil {
log.Printf("plugin page: starting the plugin host: %v", err)
}
}()
t := time.NewTimer(pageHostWait)
defer t.Stop()
select {
case <-done:
case <-t.C:
case <-ctx.Done():
}
}
// servePluginPage serves a file of a plugin's page, by its token, and on
// a page served to a browser (web) the page's local service too.
func servePluginPage(rw http.ResponseWriter, r *http.Request, web bool) {
rest := strings.TrimPrefix(r.URL.Path, pluginPagePrefix)
tok, rel, ok := strings.Cut(rest, "/")
if !ok || len(tok) != 32 {
http.NotFound(rw, r)
return
}
// the page's or the panel's folder, by its token
dir, entry, hosted := "", "", false
var page *pluginPage
pages, panels := windowParts()
for i, p := range pages {
if hmac.Equal([]byte(p.token), []byte(tok)) {
dir, entry, hosted = p.dir, p.file, p.hosted
page = &pages[i]
}
}
// the service's paths are never a file of the page's
if strings.HasPrefix(rel, pageServicePath) {
if !web || page == nil || page.servicePort() == 0 {
http.NotFound(rw, r)
return
}
servePageService(rw, r, page, tok)
return
}
if r.Method != http.MethodGet && r.Method != http.MethodHead {
http.Error(rw, "method not allowed", http.StatusMethodNotAllowed)
return
}
for _, p := range panels {
if hmac.Equal([]byte(p.token), []byte(tok)) {
dir, entry, hosted = p.dir, p.file, p.hosted
}
}
if dir == "" {
http.NotFound(rw, r)
return
}
// the page itself, of a plugin with a part for the host: that part is
// up before the page is (pageHost)
if hosted && rel == entry {
pageHost(r.Context())
}
h := rw.Header()
h.Set("Content-Security-Policy", pagePolicy(r, tok))
h.Set("X-Content-Type-Options", "nosniff")
h.Set("Referrer-Policy", "no-referrer")
// no Cross-Origin-Resource-Policy: to the page's sandboxed frame, an
// origin of its own, its own files are another origin's, and
// same-origin (or same-site) would block every one of them
h.Set("Cache-Control", "no-cache")
if rel == pluginBridgePath {
h.Set("Content-Type", "text/javascript; charset=utf-8")
http.ServeContent(rw, r, "bridge.js", time.Time{}, strings.NewReader(string(pageBridgeJS)))
return
}
file, ok := plugin.FileIn(dir, rel)
if !ok {
http.NotFound(rw, r)
return
}
// ServeContent, not ServeFile: ServeFile sends .../index.html to ./,
// which a page's own links needn't follow.
f, err := os.Open(file)
if err != nil {
http.NotFound(rw, r)
return
}
defer f.Close()
st, err := f.Stat()
if err != nil || st.IsDir() {
http.NotFound(rw, r)
return
}
http.ServeContent(rw, r, filepath.Base(file), st.ModTime(), f)
}
// apiFramed is whether r is a request for /api that no page of the window's
// own makes: one from a sandboxed frame (Origin: null, which a plugin's
// page's fetch would send were its policy not to stop it), one that loads
// /api into a frame, or one another site's page sends. The desktop
// window's /api has no key, so this is what keeps a plugin's page out.
func apiFramed(r *http.Request) bool {
if !strings.HasPrefix(r.URL.Path, "/api/") {
return false
}
if r.Header.Get("Origin") == "null" {
return true
}
switch r.Header.Get("Sec-Fetch-Dest") {
case "iframe", "frame", "embed", "object":
return true
}
return r.Header.Get("Sec-Fetch-Site") == "cross-site" && r.Header.Get("Sec-Fetch-Dest") != "document"
}
// pluginPageRoutes are the routes of the plugins' pages and panels. web is
// whether the window is a browser's (isWeb): only there is a page's local
// service served through this server (servePageService), since only there
// can 127.0.0.1 be another computer than this one.
func pluginPageRoutes(mux *http.ServeMux, web bool) {
mux.HandleFunc(pluginPagePrefix, func(rw http.ResponseWriter, r *http.Request) { servePluginPage(rw, r, web) })
mux.HandleFunc("GET /api/plugin-pages", func(rw http.ResponseWriter, r *http.Request) {
out := pluginPages()
if out == nil {
out = []pluginPage{}
}
for i := range out {
if web && out[i].servicePort() > 0 {
out[i].Service = strings.Repeat("../", strings.Count(out[i].file, "/")) + pageServicePath
}
}
writeJSON(rw, out)
})
mux.HandleFunc("GET /api/plugin-panels", func(rw http.ResponseWriter, r *http.Request) {
_, out := windowParts()
if out == nil {
out = []pluginPanel{}
}
writeJSON(rw, out)
})
// what a page or a panel asked the window to read: only what its
// package declared, and never a secret
mux.HandleFunc("POST /api/plugin-pages/read", func(rw http.ResponseWriter, r *http.Request) {
var in struct {
Spec string `json:"spec"`
Read string `json:"read"`
Params map[string]any `json:"params"`
}
if err := json.NewDecoder(http.MaxBytesReader(rw, r.Body, 64<<10)).Decode(&in); err != nil {
fail(rw, err)
return
}
name, reads, ok := windowOf(in.Spec)
if !ok {
fail(rw, errors.New("no plugin page "+in.Spec))
return
}
if !slices.Contains(reads, in.Read) {
rw.Header().Set("Content-Type", "application/json")
rw.WriteHeader(http.StatusForbidden)
_ = json.NewEncoder(rw).Encode(map[string]string{"error": fmt.Sprintf("%s's package doesn't ask to read %q", name, in.Read)})
return
}
v, err := pageRead(in.Read, in.Params)
if err != nil {
fail(rw, err)
return
}
writeJSON(rw, v)
})
// a page's or a panel's own options, as plugins.json keeps them: no
// other plugin's
mux.HandleFunc("POST /api/plugin-pages/options", func(rw http.ResponseWriter, r *http.Request) {
var in struct {
Spec string `json:"spec"`
Options json.RawMessage `json:"options"`
}
if err := json.NewDecoder(http.MaxBytesReader(rw, r.Body, 64<<10)).Decode(&in); err != nil {
fail(rw, err)
return
}
if _, _, ok := windowOf(in.Spec); !ok {
fail(rw, errors.New("no plugin page "+in.Spec))
return
}
if len(in.Options) > 0 && string(in.Options) != "null" {
var opts map[string]any
if err := json.Unmarshal(in.Options, &opts); err != nil {
fail(rw, errors.New("a page's options are an object"))
return
}
// a page that sets them over and over would start the
// host, every plugin's, again each time
if !pageSetAllowed(in.Spec, time.Now()) {
http.Error(rw, "a page sets its options once a second at most", http.StatusTooManyRequests)
return
}
if err := plugin.SetPageOptions(in.Spec, opts); err != nil {
fail(rw, err)
return
}
}
for _, e := range plugin.Load().Plugins {
if e.Spec == in.Spec {
opts := e.Options
if opts == nil {
opts = map[string]any{}
}
writeJSON(rw, opts)
return
}
}
writeJSON(rw, map[string]any{})
})
}
var pageSets = struct {
sync.Mutex
at map[string]time.Time
}{at: map[string]time.Time{}}
// pageSetAllowed is whether spec's page may set its options now: a second
// after it last did.
func pageSetAllowed(spec string, now time.Time) bool {
pageSets.Lock()
defer pageSets.Unlock()
if last, ok := pageSets.at[spec]; ok && now.Sub(last) < time.Second {
return false
}
pageSets.at[spec] = now
return true
}
// pageRead is one of plugin.PageReads.
func pageRead(read string, params map[string]any) (any, error) {
switch read {
case "providers:list":
// a name and an id each: no key, no account, no address
type prov struct {
ID string `json:"id"`
Name string `json:"name"`
}
out := []prov{}
for _, p := range provider.All() {
out = append(out, prov{ID: p.ID, Name: p.Name})
}
return out, nil
case "usage:summary":
period := usage.Today
if s, _ := params["period"].(string); s != "" {
period = usage.Period(s)
}
if !slices.Contains([]usage.Period{usage.Today, usage.Week, usage.Month}, period) {
return nil, fmt.Errorf("no period %q: today, 7d or 30d", period)
}
s := usage.Summarize(period)
type model struct {
Model string `json:"model"`
Calls int `json:"calls"`
Input int `json:"input"`
Output int `json:"output"`
Cost float64 `json:"cost"`
}
// the totals and each model's, never a key's, an account's or a
// session's
out := struct {
Period string `json:"period"`
Since time.Time `json:"since"`
Calls int `json:"calls"`
Errors int `json:"errors"`
Input int `json:"input"`
Output int `json:"output"`
Cache int `json:"cacheRead"`
Cost float64 `json:"cost"`
Models []model `json:"models"`
}{Period: string(period), Since: s.Since, Calls: s.Calls, Errors: s.Errors, Input: s.Input, Output: s.Output, Cache: s.CacheRead, Cost: s.Cost, Models: []model{}}
for i, g := range s.Models {
if i == 20 {
break
}
m := g.Model
if m == "" {
m = g.ID
}
out.Models = append(out.Models, model{Model: m, Calls: g.Calls, Input: g.Input, Output: g.Output, Cost: g.Cost})
}
return out, nil
}
return nil, fmt.Errorf("no read %q", read)
}