Repository navigation
fix(provider): limit JSON schema depth for Moonshot/Kimi - #25492
nateGeorge wants to merge 1 commit into
Conversation
…exceeds maximum limit of 10' errors
Moonshot/Kimi K2.6 rejects tool schemas with nesting depth > 10. Klaviyo and
other APIs define deeply nested anyOf structures (11-12 levels) that break
all tool calls on Kimi models.
Changes:
- add MAX_DEPTH = 9 (1 level headroom) to sanitizeMoonshot()
- add isComplex() to distinguish structural nodes from primitives
- flatten complex nodes at depth >= 9 to {type: object, additionalProperties: true}
- preserve primitives (string, number, boolean) untouched at any depth
Fixes schema depth errors without losing type safety for simple parameters.
Closes anomalyco#1010
|
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
|
The following comment was made by an LLM, it may be inaccurate: Potential Related PR FoundPR #23667: "fix: expose actual Kimi/Moonshot API errors and resolve $ref schema" This PR is related as it also addresses Moonshot/Kimi schema handling. While it focuses on exposing API errors and resolving $ref schemas, it may be relevant context for the current PR's JSON schema depth limiting fix. The search results mostly return PR #25492 itself, indicating no other currently open PRs with identical focus on limiting JSON schema depth for Moonshot/Kimi. |
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
|
Automated PR Cleanup Thank you for contributing to opencode. Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions. This PR was closed because it matched the following cleanup criteria:
PRs created within the last month are not affected by this cleanup. If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate. Thanks again for taking the time to contribute. |
Issue for this PR
Closes #25495
Type of change
What does this PR do?
Moonshot/Kimi K2.6 enforces a JSON schema depth limit of 10 levels. Tools with deeply nested schemas (e.g., Klaviyo campaign message definitions with 11-12 levels of nested
anyOf/properties) cause all tool calls to fail withschema depth exceeds maximum limit of 10.This PR adds depth-aware schema flattening to
sanitizeMoonshot()intransform.ts:MAX_DEPTH = 9(1 level headroom under Kimi's 10 limit)isComplex()distinguishes structural nodes (objects withproperties,anyOf,oneOf,allOf,items,$defs) from primitives{ type: "object", additionalProperties: true }or{ type: "array", items: { type: "object", additionalProperties: true } }string,number,boolean) pass through untouched at any depthThis preserves type safety for simple parameters while preventing the depth error on complex nested schemas. All 2,347 tests pass, including 2 new tests specifically verifying deep nesting flattening and Klaviyo-like anyOf schema handling.
How did you verify your code works?
bun testinpackages/opencode: 2,347 pass, 0 fail, 11 skip, 1 todotransform.test.ts:Checklist