Skip to content

feat(ai): add TypeScript schema format for LLM token efficiency#7

Draft
brian-mulier-p wants to merge 1 commit intofeat/use-toon-formatfrom
feat/typescript-schema-format
Draft

feat(ai): add TypeScript schema format for LLM token efficiency#7
brian-mulier-p wants to merge 1 commit intofeat/use-toon-formatfrom
feat/typescript-schema-format

Conversation

@brian-mulier-p
Copy link
Copy Markdown
Member

Closes #TODO

Adds TypeScript type definitions as a third schema format option for the AI copilot, alongside JSON and TOON.

Token comparison (flow-schema.json):

Format Chars ~Tokens vs JSON
JSON 73,473 27,749 baseline
TOON 82,703 21,521 -22%
TS 27,401 10,832 -61%

Includes an A/B/C benchmark test (ToonRegressionBenchmarkTest) to validate generation quality across formats with a real Gemini model.

… to TOON

TypeScript type definitions reduce LLM token consumption by ~61% vs JSON
(compared to TOON's ~22%), because TS notation eliminates structural
boilerplate (type/properties/items wrappers, quotes, braces) that
tokenizers split into many small tokens.

- Add generic JsonSchemaToTypeScript converter (handles $ref, allOf,
  anyOf, oneOf, enum, const, additionalProperties, validation
  constraints, deprecated field filtering)
- Add SchemaFormat enum to AbstractAiCopilot for format selection
- Add A/B/C benchmark test comparing JSON vs TOON vs TypeScript
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant