ds4 icon indicating copy to clipboard operation
ds4 copied to clipboard

server: emit GLM tool-call args with their real JSON types (fixes #569)

Open gilbert-barajas opened this issue 4 months ago • 1 comments

parse_glm_generated_message_ex hardcoded is_string="true" on every GLM tool-call argument, so numbers/arrays/booleans/null were JSON-escaped into strings ("10", "[]", "true") — which schema-validating clients (zod/ajv, Chatwise) reject. GLM's <arg_value> wire format carries no type attribute, unlike DeepSeek's DSML string="true|false" that the DSML path already honors via json_minify_raw_value.

Adds glm_arg_value_is_raw_json() — true only when the whole value is one complete, valid, non-string JSON value (number / true/false/null / [...] / {...}), reusing the json_skip_value primitive json_minify_raw_value already relies on. Plain text and JSON string literals stay quoted, so is_string is "false" for raw JSON values and "true" otherwise.

Verified with a new parser test (test_parse_glm_tool_call_arg_types): the #569 curl's args now emit max_results: 10, exclude_domains: [], safe_search: true, cursor: null, opts: {…} with correct types, while query stays a string. Also fixes an existing test that had encoded the bug ("timeout": "10" → "timeout": 10). +70/−2.

Fixes #569

gilbert-barajas avatar Jul 20 '26 17:07 gilbert-barajas

Verified end-to-end on M3 Ultra Mac Studio (Metal backend, GLM-5.2-UD-Q2_K_RoutedQ2K.gguf): applied the helper + call-site + test hunks to my fork, rebuilt, and ran both unit tests and a live OpenAI-compatible request. test_parse_glm_tool_call_arg_types passes, and a real set_todos call now emits "todos": [{...}] as a native array instead of a stringified value. Plain-text string args remain correctly quoted. Thanks for the clean fix.

garnetlyx avatar Jul 25 '26 09:07 garnetlyx