Skip to content
This repository was archived by the owner on Feb 25, 2026. It is now read-only.

fix: handle GLM model JSON array output format#138

Closed
mikij wants to merge 3 commits intoKilo-Org:devfrom
mikij:fix/json-to-text-response
Closed

fix: handle GLM model JSON array output format#138
mikij wants to merge 3 commits intoKilo-Org:devfrom
mikij:fix/json-to-text-response

Conversation

@mikij
Copy link
Copy Markdown
Contributor

@mikij mikij commented Feb 5, 2026

Context

GLM-4.7 models (via Kilo Gateway) output code as JSON arrays instead of plain text:
[{@angular/core: import { ComponentFixture }, @angular/testing: import { render }}]
This format is unreadable in the UI and breaks normal text display.

Implementation

Added a JSON array to plain text conversion in ProviderTransform.normalizeMessages() (packages/opencode/src/provider/transform.ts):

  1. Condition: Only applies to kilo provider with z-ai/glm model IDs
  2. Logic: Detects string content starting with [ and ending with ], parses as JSON, converts array of objects to key: value format
  3. Result: [{"@angular/core": "import {...}"}] → @angular/core: import {...}
    The transform:
  • Handles nested objects (stringifies them)
  • Preserves whitespace handling
  • Only processes assistant role messages with string content
  • Gracefully falls back for invalid/non-matching JSON

Screenshots

before after
[{"@angular/core": "import { ComponentFixture }"}] @angular/core: import { ComponentFixture }

How to Test

  1. Start a code session with z-ai/glm-4.7 model
  2. Ask the model to write code (e.g., "Write an Angular component test file")
  3. Verify the response displays as readable text, not JSON array structure

Get in Touch

https://discord.com/channels/1349288496988160052/1391109167275577464/1468977195463741481

@mikij
Copy link
Copy Markdown
Contributor Author

mikij commented Feb 5, 2026

Found some new issues. It is not good yet, need to investigate further what is happening

@mikij mikij marked this pull request as draft February 5, 2026 17:08
@mikij mikij closed this Feb 6, 2026
@mikij mikij deleted the fix/json-to-text-response branch February 6, 2026 07:56
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant