Repository navigation
Conversation
DeepSeek can emit raw JSON control characters or invalid escapes inside generated source code even with strict tool calling. Preserve those string values without guessing at ambiguous JSON structure, report sanitized parser diagnostics, and validate tool inputs before handlers run.
🦋 Changeset detectedLatest commit: d57e8d8 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Safely recovers malformed tool-call JSON string content and validates parsed arguments before any tool handler executes.
DeepSeek can return HTTP 200 tool calls whose
function.argumentscontain raw control characters, invalid JSON escapes from generated source code, or ambiguous structural errors even when strict tool calling uses the beta endpoint. The old parser either rejected safely recoverable string content or used a regular expression that misidentified nested JavaScript template literals.The parser now follows a deliberately narrow path:
Raw U+0000–U+001F characters are encoded so the decoded string value is unchanged. Invalid JSON escapes such as
\'or\dhave only their backslash escaped, preserving the exact original characters. Unescaped quotes, missing separators, and malformed structure are not guessed at. Errors include only tool name, finish reason, argument length, category, and position.This also closes a safety gap where Zod schemas were converted for provider requests but were not applied at runtime before local, Inngest, or MCP tool handlers.
Live beta-endpoint stress testing produced two malformed responses among six HTTP 200
tool_callsresponses. The invalid-escape response is recovered byte-semantically by this patch; the ambiguous unescaped-quote response remains an error as intended.Validation: 73/73 tests including both MCP transports, TypeScript, ESLint, package build, a full 36,341-character captured invalid-escape fixture, and a fresh 45,352-character real DeepSeek call after reinstall and restart.
Partially addresses #329.
Changelog