Skip to content

fix(kosong): correct type inference when enum/const contradicts expli…#137

Open
logic10492 wants to merge 2 commits into
MoonshotAI:mainfrom
logic10492:fix/schema-type-mismatch
Open

fix(kosong): correct type inference when enum/const contradicts expli…#137
logic10492 wants to merge 2 commits into
MoonshotAI:mainfrom
logic10492:fix/schema-type-mismatch

Conversation

@logic10492
Copy link
Copy Markdown

 ## Related Issue

 N/A — no prior issue opened for this bug.

 ## Problem

 When a tool JSON schema explicitly declares a `type` that contradicts the actual values in `enum` or `const` (e.g. `type: 'object'` with `enum: ['move', 'copy']`), `normalizeKimiToolSchema` previously only  inferred the type when it was missing. It did **not** correct a mismatched explicit type, leaving an invalid schema that could propagate downstream.

 ## What changed

 Updated `normalizeProperty` in `packages/kosong/src/providers/kimi-schema.ts` so that when `enum` or `const` is present, the function now:

 1. Infers the type from the enum/const values if `type` is absent (existing behavior preserved).
 2. Corrects the `type` if it is already present but contradicts the inferred type from enum/const values.

 Added a test case in `kimi-schema.test.ts` covering both `enum` and `const` mismatch scenarios.

 ## Checklist

 - [x] I have read the [CONTRIBUTING](https://github.com/MoonshotAI/kimi-code/blob/main/CONTRIBUTING.md) document.
 - [x] I have explained the problem above (no linked issue).
 - [x] I have added tests that prove my feature works.
 - [x] Ran `gen-changesets` skill — `.changeset/fix-schema-enum-type-inference.md` added.
 - [x] Ran `gen-docs` skill, or this PR needs no doc update. <!-- needs no doc update -->

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 28, 2026

🦋 Changeset detected

Latest commit: 06d9255

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@moonshot-ai/kosong Patch
@moonshot-ai/kimi-code Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@logic10492 logic10492 force-pushed the fix/schema-type-mismatch branch from 3891fba to 06d9255 Compare May 28, 2026 05:38
@logic10492
Copy link
Copy Markdown
Author

I first encountered this issue while integrating with xcodebuildmcp. Although the upstream project has since addressed it on their end, I believe applying this
fix at the framework level improves overall compatibility
and prevents similar issues for other integrations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant