feat: add TOON type with automatic JSON-to-TOON conversion #10
+973
−0
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.
Summary
This PR introduces a new
TOONtype that automatically converts JSON payloads to compact TOON format when unmarshaling. The type implements standard Go interfaces for seamless integration with JSON, text formats, and databases.Changes
New TOON Type (
api.go)type TOON []bytewith complete interface implementationsjson.Marshaler/Unmarshaler- Automatic JSON ↔ TOON conversionencoding.TextMarshaler/Unmarshaler- Text format supportdatabase/sql.Scanner/driver.Valuer- Database operationsfmt.Stringer- String representation viaString()methodIsNil()for checking empty/nil valuesCodec Integration
internal/codec/normalize.go: Added support forencoding.TextMarshalerinterfaceinternal/codec/unmarshal.go: Added support forencoding.TextUnmarshalerinterfaceDocumentation
README.md: Added comprehensive section "Capturing Tool Call Payloads with the TOON Type" (lines 107-188)Examples
examples/json_payload/main.go: Demonstrates JSON payload capture with automatic conversionexamples/toon_type/main.go: Shows basic TOON type operationsexamples/tool_response/main.go: Illustrates tool call workflow storageTests
tests/toon_type_test.go: Comprehensive test coverageTest Plan