UNPKG

zon-format

Version:

ZON: The most token-efficient serialization format for LLMs - beats CSV, TOON, JSON, and all competitors

51 lines (49 loc) 1.47 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ZonOutputParser = void 0; const output_parsers_1 = require("@langchain/core/output_parsers"); const index_1 = require("../index"); /** * Parser for ZON (Zero Overhead Notation) output. */ class ZonOutputParser extends output_parsers_1.BaseOutputParser { constructor() { super(...arguments); this.lc_namespace = ["zon", "output_parsers"]; } /** * Returns instructions on how to format the output as ZON. * @returns Format instructions string */ getFormatInstructions() { return `Your response must be formatted as ZON (Zero Overhead Notation). ZON is a compact format for structured data. Rules: 1. Use 'key:value' for properties. 2. Use 'key{...}' for nested objects. 3. Use 'key[...]' for arrays. 4. Use '@(N):col1,col2' for tables. 5. Use 'T'/'F' for booleans, 'null' for null. Example: user{name:Alice,role:admin} items:@(2):id,name 1,Item A 2,Item B `; } /** * Parses the output text into a typed object. * @param text - The output text to parse * @returns Parsed object */ async parse(text) { try { const cleaned = text.replace(/```(zon|zonf)?/g, "").trim(); return (0, index_1.decode)(cleaned); } catch (e) { throw new Error(`Failed to parse ZON output: ${e.message}`); } } } exports.ZonOutputParser = ZonOutputParser;