Commit Graph
6 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 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