Commit Graph
8 Commits
Author SHA1 Message Date
ggbdpq 837ea5f565 gateway: a Kimi tool schema with items is an array, not its enum's string, as Gemini's is now (#3867)
yetone, #3867: kimiSchemaType and collectUntypedEnums read an untyped
schema's enum or const before its keywords, so a tool's
{"items":{"type":"string"},"enum":["a","b"]} reached Kimi typed "string"
with items beside it — the shape its Gemini sibling went out in until
d71362af made geminiSchemaType read an object's or array's keywords
(properties, items, keywordType) before its values, and Antigravity
turned that turn away over them.

- collectUntypedEnums: of an untyped node typed from its enum or const,
  its properties or items (keywordType, object or array) say the type
  first; a pattern's or minimum's string or number still loses to the
  values, as before (an integer enum beside a minimum stays integer).
- kimiSchemaType: the same keywords before the enum or const, a $ref's
  target included; the one its branches say unchanged.
- Whether Kimi refuses items on a string is not known (no report of it,
  no real Kimi request tried; #3867 leaves that to a real account); the
  two are kept apart either way, as Gemini's are.

Tests (kimi_schema_test.go): TestKimiToolEnumTypesItemsBeforeEnum, the
issue's shape through kimiToolEnumTypes and a $defs target with items
and a string enum through kimiToolRefTypes, an enum without items or
properties still typed from its values.

Run, in a worktree at upstream/main e056779a:
- go test -tags nogui ./internal/gateway -run
  'TestKimiToolEnumTypesItemsBeforeEnum' -count=1, before the change:
  FAIL (display typed "string" with items beside it, filter "string"
  with properties, the $ref's target "string"); after: ok, and
  TestKimiToolEnumTypes, TestKimiToolRefTypes and TestKimiLockedSampling
  pass as they were.

Fixes #3867

Generated-by: GLM-5.3-Flash (ZCode)
2026-11-01 10:22:56 +08:00
ggbdpq 7bdf08f18d gateway: no type beside the $ref a Kimi schema's target is
kimiToolRefTypes wrote a type into each schema a tool's $refs reach that
has none. When the target was itself a $ref — zod writes one beside what
it changed of a reused schema, a format and a description among them, as
Codex's automation_update's targetThreadId reaches {"format":"uuid",
"description":"tt","$ref":"#/$defs/__schema1"} — the type went beside
that inner $ref, and Moonshot refuses one there, 400 "At path
'$defs.__schema14': when using $ref, type should be defined in the
referenced schema instead of the parent schema" (#3205), so every turn
failed though the tool is never called. The plugin side had the same bug
and fixed it in kimi-work 0.1.5.

The chain a $ref names is now followed to the schema it ends at, and it
is there the type goes, or nowhere when the chain ends at a ref to
nowhere or never ends: schemaTypes already resolved chains to say what
the type is, so only the place it is written moves. Codex's own
automation_update schema (the fixture its tests and magpie's root-union
tests share) goes as it was sent: its defs are notes beside a $ref to a
typed target, which Kimi takes.

Fixes #3205

Generated-by: GLM-5.3-Flash (ZCode)
2026-11-01 10:22:56 +08:00
ggbdpq 7804dfbb03 gateway: drop the locked sampling fields for Kimi on Volcengine Ark too
Volcengine Ark's plans lock the sampling parameters of the Kimi models
they serve: any request carrying temperature != 1 is refused 400
"Volcengine Ark: `temperature` only 1 is allowed for this model"
(#4495, kimi-k3.1-pro / kimi-k3 / kimi-k2.8-preview at
ark.cn-beijing.volces.com/api/coding/v3), before any token is read —
clients that send their own defaults (Claude Code, Copilot) fail every
call, and a routing group spends its failover window on each try.

kimiLockedSampling already drops temperature and top_p for the locked
models on Moonshot's own endpoints (#1197), but its isKimi guard knows
only Moonshot's hosts and presets, so the same models behind an Ark
host went through with the fields. The refusal names the model ("for
this model"), not the path, and the preset's Agent Plan and pay-as-you-
go regions list the same kimi-kX.Y models, so the guard now also takes
isArk — the ark.<region>.volces.com check the draw and video code
already uses, which covers the preset's plans and a provider added by
hand — and kimiLockedSamplingModel keeps deciding per model, as it
already does for kimi-k2.5 and later, kimi-for-coding* and k3*. Ark's
other models (doubao, glm, deepseek, minimax) are untouched, as is
everyone not served by Moonshot or Ark.

Run: TestKimiLockedSampling in internal/gateway grew four cases (the
coding plan's chat and anthropic routes, an Ark model the server
doesn't lock, a provider added by hand on an Ark host): the three drop
cases fail on the unmodified code and pass with it, the keep case
passes throughout. go test -tags nogui ./internal/gateway ok (499s);
gofmt clean; go vet -tags nogui on darwin, linux and windows clean;
go build -tags nogui ./... on darwin, linux and windows ok.

Generated-by: GLM-5.3-Flash (ZCode)

Reviewed and run by yetone at the batch head over cac655c14 (this commit,
the four others from ggbdpq's #4495/#4548/#4512/#3260 patches and the
#4548 follow-up), on mote:
- gofmt -l clean; go vet ./... for darwin, linux (-tags nogui), windows;
  go build ./... for darwin and windows.
- go test -tags nogui -count=1 -timeout 45m ./...: every package ok but
  internal/gui, with two filed reds: TestSettingsSaveKeepsWhatItDoesNotSend
  (#4514), red alone at origin/main cac655c14 too, and TestColdTurnsTaken
  (#4510), red only in the full run. Rebased afterwards onto e94fb18b8,
  a usage-page change that touches none of these files.
- Windows (xiaomi-gpu): go test -run 'TestVSCode|TestClaudePicker'
  ./internal/agent ok. TestCopilotFolderFromAnIDEPluginIsNotTheCLI is red
  there at cac655c14 too (#1827).
- Broken by hand: guard back to !isKimi(p, to) -> three TestKimiLockedSampling subtests red (volcengine coding plan, its anthropic endpoint, a hand-added Ark host). Not tried: a real Volcengine Ark Kimi request.
2026-10-31 20:54:37 +08:00
yetone d71362afcd gateway: a Gemini tool schema with items is an array, not its enum's string, and Antigravity gets items only on arrays (ferock)
ferock on Discord: Claude Code, model group/gemini-3-8-flash on a local
magpie whose group is served by a remote magpie's Antigravity, 400
"Remote magpie: Antigravity: GenerateContentRequest.tools[0].
function_declarations[19].parameters.properties[display].items: field
predicate failed: $type == Type.ARRAY". It worked in the morning and
broke after updating. The tool's literal schema wasn't posted, and no
Claude Code 2.1.311 built-in has a display property with items (searched
the binary), so it is an MCP tool of theirs.

Cause: geminiToolTypes (68ee4117a, v0.1.1624, 10-27 01:26) runs in
forwardOnce for any body whose model names Gemini, the local magpie's
forward to a remote magpie included. geminiSchemaType typed an untyped
schema from its enum/const values before its keywords, so
{"items":{...},"enum":["a","b"]} went on as type "string" with items
beside it. The remote's plainSchema kept the explicit type and the
items, and Google refused the whole turn. Before 68ee4117a the same node
reached plainSchema untyped and was inferred an array.

- geminiSchemaType: an object's or array's keywords (properties, items
  and the rest, keywordType, split out of schemaTypes unchanged) decide
  before enum/const values.
- plainSchema (the remote's Antigravity side, so a local magpie from
  before is served too): items/minItems/maxItems are kept only on an
  array and properties/required/min-maxProperties/propertyOrdering only
  on an object, as JSON Schema reads them; of a type list it takes the
  type its items or properties are for (["string","array"] with items is
  an array, not a string with items).
- docs/subsystems/gateway-routing.md says both.
- Sibling not changed: kimiSchemaType/collectUntypedEnums still type
  such a node from its enum; whether Kimi refuses items on a string is
  unknown, filed as #3867.

Tests (antigravity_display_items_test.go): the shape the error points to
(an untyped display with items and a string enum, plus properties with a
const) through geminiToolTypes, and through parseAnthropic +
buildCodeAssist(antigravity) as Claude Code sent it, as this version's
local passes it on, and as an older local passes it on (display typed
"string", type lists, a string with object/array keywords); every node
sent has items only as an array and properties only as an object.

Run, in a worktree at origin/main 32ea16c5a:
- go test -tags nogui ./internal/gateway -run 'CodeAssist|Codeassist|
  Gemini|Schema|Antigravity|Kimi|Plain|Grok|OneOf|Tool|Vertex|Google|
  Shape|Enum' -count=1: ok (60s)
- gofmt -l internal/gateway: clean; go vet -tags nogui (darwin),
  GOOS=linux go vet -tags nogui, GOOS=windows go vet on internal/gateway:
  clean
Broken by hand: gemini_schema.go back to origin/main,
TestGeminiToolTypesItemsBeforeEnum and TestAntigravityItemsOnlyOnArrays
FAIL (display typed "string"); codeassist.go back to origin/main,
TestAntigravityItemsOnlyOnArrays FAILs (items, minItems, properties on
type "string").

Not tried: the reporter's literal tool schema (not posted; the fixture is
the shape the error and the update point to), a real Antigravity
account, and a real two-magpie setup. Not run: the whole gateway
package or ./... (another session's full internal/gateway run was on the
machine, load ~60-75).
2026-10-27 16:34:19 +08:00
yetone 68ee4117af gateway: a Gemini model's untyped tool schemas go typed (Vertex refused cua-driver's drag)
kthink on Discord: dsh with cua-driver's MCP tools on Command Code's
google/gemini-3.8-flash (the commandcode plugin), every request 400
INVALID_REQUEST from Vertex: "`mcp__cua-driver__drag` functionDeclaration
`parameters.target` schema didn't specify the schema type field."
cua-driver's drag schema before cua's #4888 has target as an anyOf of an
untyped oneOf and null, and scope a const with no type. Command Code's
gateway turns JSON Schema into Vertex's Schema object, whose type is
required, and an untyped node stays untyped.

geminiToolTypes (forwardOnce, so plugin requests too) is keyed on the
model id (last '/' segment starts with "gemini"), not the provider:
each untyped schema under tools' function.parameters / parameters /
input_schema gets the type its enum/const, keywords or branches say,
null left out; {} or a description alone is a string, a tool root an
object. Mixed-type unions, unresolved $ref/unions and anything under
not/if are left as they came. Written in place after the brace, so the
rest of the body is unchanged. withTypes no longer writes a trailing
comma into an empty {} (it produced invalid JSON there).
Google's own Gemini API / Code Assist (parametersJsonSchema) and
Antigravity (plainSchema) bodies have no such tools and are not walked.

Run at this tree, rebased on origin/main 8f023b511 (tests and vet run again there; GOMODCACHE/GOCACHE pinned):
- go test ./internal/gateway/ -run 'Gemini|Kimi|Grok|OneOf|PlainSchema|Tool|LoopGuard|Doc' -count=1: ok
- gofmt -l internal/gateway/: clean
- go vet ./internal/gateway/ (darwin), GOOS=linux go vet -tags nogui,
  GOOS=windows go vet: ok; go build ./... for darwin, linux (nogui), windows: ok
- Not run: the full ./... suite (machine load ~200, other sessions' suites).

Broken by hand:
- geminiToolTypes call commented out of forwardOnce:
  TestGeminiToolTypesCuaDriverDrag red on chat, messages and responses.
- emptyObjectAt check replaced by true: TestGeminiToolTypes red, invalid JSON.

Tests: TestGeminiToolTypesCuaDriverDrag uses cua-driver's literal old drag
schema (testdata/cua_driver_drag_untyped.json) through the server on
/v1/chat/completions, /v1/messages and /v1/responses; a GPT model on the
same provider gets the tools byte for byte. TestGeminiToolTypes covers the
type rules, and that claude/gpt/gemma/kimi ids get the body bytes.Equal.

Not tried: a real Command Code account or a real Vertex request; the
schema's acceptance by Vertex is from its documented Schema object and
cua's own Vertex lint (cua-driver-testkit vertex.rs), not a live call.
2026-10-27 01:28:39 +08:00
yetone 129d8b08a5 gateway: a schema a tool's $ref reaches goes to Kimi with a type
chaosy on Discord: Codex on Kimi Code k3 failed every request, 400 "not
a valid moonshot flavored json schema … $defs.__schema20 … must be
defined". Moonshot's validator expands each $ref and refuses a target
with no type ("At path 'properties.b': detected infinite recursion
without termination condition"), though the same schema written inline
passes. Codex sends its MCP and Codex App tools as zod's $defs and types
a def with properties or an enum, but leaves a oneOf or allOf def as it
was, so the whole request fails.

kimiToolRefTypes, scoped by isKimi and run in forwardOnce after
kimiToolEnumTypes (chat, Anthropic and Codex's Responses routes all pass
there), writes a type after the brace of each untyped $ref target: the
one its keywords or branches say, a type array when they differ, every
type when nothing does. {} targets, anyOf targets (Kimi refuses a type
beside an anyOf) and pure $ref chains are left alone. kimiToolEnumTypes
now also types an enum of one type plus null as [T,"null"], the one type
array Kimi takes beside an enum. Kimi doesn't count as a moved
subscription, so no plugin path reaches it.

Measured against the real Kimi Code chat endpoint
(api.kimi.com/coding/v1/chat/completions, a key without a plan, so a
schema that passes validation gets 403 access_terminated_error and a
refused one gets 400 first):
- Codex 0.162.1's processed shapes: 400 at properties.b before, 403
  after.
- Raw shapes (properties-only, minLength-only, const, [1,null] enum,
  description-only and oneOf-of-refs defs): 400 before, 403 after.
- The zod-built Codex App automation_update forms: 403 before and after.
- [T,"null"] plus enum, a type array beside oneOf, and every type beside
  a description: 403.
The Anthropic endpoint answers 403 before it validates, so it couldn't
be probed; the same rewrite reaches it.

Tests: TestKimiToolRefTypes posts on /v1/chat/completions, /v1/messages
and /v1/responses to Kimi and to another provider, which gets the tools
unchanged. With the forwardOnce line removed it fails on all three
Kimi routes. TestKimiToolEnumTypes now expects [T,"null"] for
["a",null], and fails with that branch removed.

Run at this head: gofmt -l (clean); go vet ./..., GOOS=linux go vet
-tags nogui ./..., GOOS=windows go vet ./... (clean);
set -o pipefail; HOME=<sandbox> go test -timeout 45m ./... at
33dbdcc52 plus this change: exit 0, all 64 packages ok (internal/gateway
1203.9s).
2026-10-19 16:38:24 +08:00
Andelu 64498df78f kimi: 将被拒绝的采样参数改写为可接受的值 (#1197)
* kimi: rewrite refused sampling params to the accepted values

VS Code Copilot's chat hardcodes temperature 0.1 and top_p 1, which Kimi
Code's per-model whitelist refuses with 400 "invalid temperature: only 1
is allowed for this model" before any token is read. Rewrite them to the
accepted values (1, 0.95) in the body before forwarding, and add them when
absent; a request already carrying them, or going to another provider, is
left as it was. Tested with the four cases: refused, absent, accepted,
another provider.

* kimi: drop temperature/top_p before forwarding to Kimi Code K models

VS Code Copilot chat sends temperature:0.1 and top_p:1, which Kimi Code rejects

with 400 "invalid temperature: only 1 is allowed for this model". Instead of

rewriting to fixed accepted values, remove the fields for Kimi Code K models

only, so the server fills in the value each model and mode wants.

Scope is narrowed to the Kimi Code membership endpoints (kimi-code presets and

api.kimi.com/ai/coding) and K models (kimi-*, kN), so Moonshot pay-as-you-go

(api.moonshot.ai/cn) and moonshot-v1-* keep the user temperature.

Tests cover the refused Copilot request, absent fields, already-accepted

values, Anthropic endpoint, Moonshot pay-as-you-go keeping user temperature,

and another provider left untouched.

* kimi: drop locked sampling fields on both Kimi platforms, for the models that lock them

A review of the last commit found the rewrite missed Moonshot's pay-as-you-go API: kimi-k2.5 and later there lock temperature and top_p the same as Kimi Code's models (400 "invalid temperature: only 1 is allowed for this model", CherryHQ/cherry-studio#19601), so a Copilot user on a Moonshot key with kimi-k2.6 was still refused. The host check is isKimi again — both platforms — and the model check narrows to the ones that lock the fields: kimi-for-coding* and k3* on Kimi Code, kimi-k2.5 and later on either. moonshot-v1-*, kimi-k2-0905-preview, kimi-k2-thinking and kimi-latest take a range and keep the user's values.

TestKimiLockedSampling adds Moonshot host cases both ways (kimi-k2.6 loses the fields, kimi-k2-0905-preview keeps 0.1), so swapping the host check between the platforms fails a test, and each case asserts its own upstream body.

* kimi: test the locked-sampling boundaries and the k3 and vendor-prefixed names

TestKimiLockedSampling now covers the cases a mutation could slip past:
Kimi Code's k3 (the bare-k branch), kimi-k2.5 (the minor >= 5 boundary),
kimi-k2-thinking keeping its temperature (k2 without a version dot is not
locked), and a relay's vendor-prefixed moonshotai/kimi-k2.6 (the vendor
strip). Each of the three surviving mutants from review — minor >= 6, no
bare-k branch, no vendor strip — now fails its subtest.
2026-10-10 17:47:13 +08:00
yetone 509e8444d1 gateway: a tool schema with an enum and no type goes to Kimi with the type its values have (#886) — Kimi Code refused a request whose tools had cua-driver's parse_visual_regions, 400 "tools.function.parameters is not a valid moonshot flavored json schema … At path 'properties.options.properties.kinds.anyOf.items': type is not defined": its items were {"enum":["text","icon"]}, and the whole request failed though the tool was never called. To Moonshot and Kimi Code (api.moonshot.ai/.cn, api.kimi.com/.ai, or a moonshot/kimi preset) each schema in the tools with an enum or a const and no type is now given the type its values all have (string, integer, number, boolean), written in place after its brace, through properties, items, anyOf/oneOf/allOf, $defs and the rest; values of mixed types or with a null are left as they were, and other providers are sent the tools unchanged. TestKimiToolEnumTypes fails without the change. go vet, go build (darwin, GOOS=linux nogui, GOOS=windows) and go test -tags nogui ./... under a temp HOME pass. 2026-10-05 17:09:51 +08:00