Files
magpie/internal/gateway/copilot_gemini_schema.go
T
yetone 46e338923b copilot gemini: unions fold to one object, $ref branches resolve, a nullable keeps no type, a bare array gets items (Novello42 on X)
DaVinci42's four cases on #4374 (v0.1.3925), fixed in the Copilot Gemini
tool-schema translation only:

- copilotGeminiToolUnions renamed a disjoint object anyOf to oneOf, which
  Copilot's Gemini takes with 200 but strips of its branches, so the model
  sent a string. The rename is gone; copilotGeminiToolShapes folds the
  branches into the one object (same-named properties join their enums, so
  a discriminator keeps "project" and "none").
- a union of local $ref branches is resolved against $defs/definitions
  (a copy; a target that refers on is not followed) before it is judged,
  instead of being dropped to an untyped string.
- a type written beside a nullable single-branch anyOf is removed (400).
- an array with no items gets items {} (typed after by geminiTypes) (400).

Run (mote, -tags nogui): TestCopilotGeminiFoldsCodexUnions,
TestCopilotGeminiReporterSchemas (the reporter's four schemas verbatim),
TestCopilotGeminiShapesLeaveOthersAlone (claude / no agent: body unchanged),
and the TestCopilot*/TestGeminiTypes*/TestAntigravity* set pass. With the
three changed non-test files put back to origin/main the first two go red
(all four reporter subtests). gofmt clean; go vet darwin/linux/windows and
the gateway package run: see the next commit/tag notes.
Not tried: a live Copilot account (the fake refuses by the reporter's
recorded rules).
2026-11-13 10:40:26 +08:00

27 lines
1.0 KiB
Go

package gateway
import (
"github.com/tidwall/gjson"
"github.com/yetone/magpie/internal/provider"
)
// copilotGemini is whether body goes to a Gemini model served by a Copilot
// account.
func copilotGemini(p provider.Provider, body []byte) bool {
return p.Account != nil && p.Account.Agent == "copilot" && geminiNamed(gjson.GetBytes(body, "model").String())
}
// copilotGrokFlat is a Responses body to Copilot's Grok with Codex's
// namespaced functions flat and their parameters objects at the root: the
// backend behind Copilot turns a request with either away, and Copilot's
// word for it is a bare status (#4374), so nothing teaches magpie to do it
// after a refusal. The calls come back under their namespaces
// (namespacedIn). Another vendor's tools go as they came.
func copilotGrokFlat(p provider.Provider, to provider.Protocol, body []byte) []byte {
if to != provider.Responses || p.Account == nil || p.Account.Agent != "copilot" ||
!grokModel(gjson.GetBytes(body, "model").String()) {
return body
}
return provider.GrokFlatBody(body)
}