Files
plugins/packages/kimi-work/tests
yetone d324a96e1a kimi-work 0.1.5: tool schemas Kimi's moonshot check refuses go in a shape it takes (#287)
chai-j: every Codex message on Kimi Work failed, 400 "tools.function.
parameters is not a valid moonshot flavored json schema, details: <At
path '$defs.__schema20': when using $ref, type should be defined in the
referenced schema instead of the parent schema>". The plugin passed the
body through as sent. Codex's MCP and app tools are zod's toJSONSchema
with reused schemas as $defs, and zod 4 writes a schema derived from a
reused one as a $ref beside what it changed: z.number().min(0) reused,
then .int() and reused itself, is $defs.__schema1 =
{"type":"integer","maximum":…,"$ref":"#/$defs/__schema0"}. Reproduced
with zod 4.6.7; the fixture is its output.

magpie's own Kimi rewrites (kimiToolEnumTypes, kimiToolRefTypes) are
scoped to api.kimi.com/moonshot hosts and presets, so a plugin's
agent-gw.kimi.com requests never got them. moonshotTools does the class
in the plugin, on tools[].function.parameters only:
- $ref beside a type: a target with no $ref of its own is written in its
  place with the parent's keywords over it (what zod's derived schema
  means: .int() of min(0) is {type:integer,minimum:0,maximum}); otherwise
  the parent's type is left out.
- type beside anyOf is left out (Kimi: "type should be defined in anyOf
  items instead of the parent schema", measured in magpie 129d8b08a).
- enum/const with no type gets its values' type, [T,"null"] with a null
  (magpie #886).
- an untyped $ref target gets the type its keywords or branches say
  (magpie 129d8b08a). Unlike magpie's kimiToolRefTypes, a target that is
  itself a $ref with keywords beside it (Codex App's
  {"format":"uuid","$ref":…}) is left alone, so no type is put beside a
  $ref.
A body with none of these goes byte for byte; a rewrite is deterministic,
so a cached prefix stays one. A Request or byte body is read as text.

Tests: tests/schema.test.mjs, with the zod fixture and Codex App's
automation_update parameters (magpie testdata) checked against the
refusal rules; 4 of its 7 tests fail on 0.1.4's index.mjs (the other
three guard the fixtures and pass-through). Package: 25 pass. Whole repo
the way CI runs it, HOME=$(mktemp -d) bun test at this head: 2056 pass,
0 fail. bun scripts/check.mjs kimi-work: ok.

Not tried: a real Kimi Work account (none here), so the rewritten tools
were never sent to agent-gw.kimi.com's validator, and the reporter's
literal __schema20 wasn't captured; the shape comes from zod's output
and the error text.
2026-10-22 01:54:22 +08:00
..