@arkadia/ai-data-format 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +198 -0
- package/package.json +1 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Arkadia Solutions
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
# @arkadia/ai-data-format
|
|
2
|
+
|
|
3
|
+
```
|
|
4
|
+
:SB@MMWBZSr,
|
|
5
|
+
,irXX7ri, iaBWMMMMM@a: :,
|
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24
|
+
,WMM0,2 :@, 0rr ;@Br2,7S ::r7,ir;rr8ZZMMMMMMSiMMa ;ai
|
|
25
|
+
rMMM8a7 ,: @0: ,: , , ,Z222X77@MW02i iZW: ,SX
|
|
26
|
+
X@SM0@: BB ;r :S ,;7XS77; ,XZZZZ82r, :;i ,, ;X:
|
|
27
|
+
;riMMM: , r , ;0 ,:7Z ;SS ; , ,: iZ@MMMMM2
|
|
28
|
+
8MM; ; Z ;i ;, XrMi B8 X7 , ,7 ,XZWMMMMMM@B
|
|
29
|
+
,WM2 7;87:8 XXMW, ,Bi ;7@i i Z ,;2aa8MWWMMMM02
|
|
30
|
+
,B@, :ZaMiBX :ZBMWr, ; XB@iiXX2:: Xa7;80Z@0a :
|
|
31
|
+
X8 r8WMaMr iZ0MM0, ,X@;;ZWX8 :S; 7:
|
|
32
|
+
,i rBWMMMr :X;WM@r ir:0@W0
|
|
33
|
+
,0@MMM2 : ;BMWi 7@MW:
|
|
34
|
+
:0MMMWi ;aBS: i8MZ:
|
|
35
|
+
XBMMW; ,;r,
|
|
36
|
+
iS0@8;
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
[](https://www.npmjs.com/package/@arkadia/ai-data-format)
|
|
41
|
+
[](https://opensource.org/licenses/MIT)
|
|
42
|
+
|
|
43
|
+
**Official Parser and Stringifier for the Arkadia AI Data Format (AID).**
|
|
44
|
+
|
|
45
|
+
AID is a schema-first, high-density data protocol designed specifically for **LLM context optimization**. It significantly reduces token usage compared to JSON by eliminating redundant syntax characters and enforcing strict typing via schemas.
|
|
46
|
+
|
|
47
|
+
## ✨ Features
|
|
48
|
+
|
|
49
|
+
- **Token Efficient:** Reduces context window usage by 15-30% compared to standard JSON.
|
|
50
|
+
- **Type Safe:** Enforces types (int, float, bool, string) explicitly in the schema.
|
|
51
|
+
- **Dual Mode:** Supports both **Named Records** (Map-like) and **Positional Records** (Tuple-like).
|
|
52
|
+
- **Zero-Dependency:** Lightweight and fast, built for high-performance pipelines.
|
|
53
|
+
|
|
54
|
+
## 📦 Installation
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
npm install @arkadia/ai-data-format
|
|
58
|
+
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## 🚀 Usage
|
|
62
|
+
|
|
63
|
+
### Importing
|
|
64
|
+
|
|
65
|
+
```typescript
|
|
66
|
+
import { encode, decode } from '@arkadia/ai-data-format';
|
|
67
|
+
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### Encoding (JavaScript Object → AID String)
|
|
71
|
+
|
|
72
|
+
Converts standard JavaScript objects into the token-optimized AID string format.
|
|
73
|
+
|
|
74
|
+
```typescript
|
|
75
|
+
const data = {
|
|
76
|
+
id: 1,
|
|
77
|
+
name: "Alice",
|
|
78
|
+
active: true
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
// Compact encoding (default)
|
|
82
|
+
const aidString = encode(data);
|
|
83
|
+
|
|
84
|
+
console.log(aidString);
|
|
85
|
+
// Output: <id:number,name:string,active:bool>(1,"Alice",true)
|
|
86
|
+
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### Decoding (AID String → AST / Value)
|
|
90
|
+
|
|
91
|
+
Parses an AID string back into a usable node structure.
|
|
92
|
+
|
|
93
|
+
```typescript
|
|
94
|
+
const input = '<score:number>(98.5)';
|
|
95
|
+
|
|
96
|
+
const result = decode(input);
|
|
97
|
+
|
|
98
|
+
if (result.errors.length === 0) {
|
|
99
|
+
console.log(result.node.value);
|
|
100
|
+
// Output: 98.5
|
|
101
|
+
|
|
102
|
+
console.log(result.node.isRecord);
|
|
103
|
+
// Output: true
|
|
104
|
+
} else {
|
|
105
|
+
console.error("Parsing errors:", result.errors);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## 📖 Syntax Guide
|
|
111
|
+
|
|
112
|
+
The AID format uses a distinct syntax to separate schema definition from data values.
|
|
113
|
+
|
|
114
|
+
### Primitives
|
|
115
|
+
|
|
116
|
+
Primitive values are explicitly typed using angle brackets `<type>`.
|
|
117
|
+
|
|
118
|
+
| Type | Input Example | Encoded Output |
|
|
119
|
+
| --- | --- | --- |
|
|
120
|
+
| Integer | `123` | `<number>123` |
|
|
121
|
+
| Float | `12.34` | `<number>12.34` |
|
|
122
|
+
| String | `"hello"` | `<string>"hello"` |
|
|
123
|
+
| Boolean | `true` | `<bool>true` |
|
|
124
|
+
| Null | `null` | `<null>null` |
|
|
125
|
+
|
|
126
|
+
### Named Records
|
|
127
|
+
|
|
128
|
+
Similar to JSON objects, but the keys are lifted into a schema definition.
|
|
129
|
+
|
|
130
|
+
**Input:**
|
|
131
|
+
|
|
132
|
+
```json
|
|
133
|
+
{ "id": 1, "name": "Test" }
|
|
134
|
+
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
**Encoded (AID):**
|
|
138
|
+
|
|
139
|
+
```text
|
|
140
|
+
<id:number,name:string>(1,"Test")
|
|
141
|
+
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
### Positional Records (Tuples)
|
|
145
|
+
|
|
146
|
+
Data without keys, where position determines meaning.
|
|
147
|
+
|
|
148
|
+
**Input:**
|
|
149
|
+
|
|
150
|
+
```javascript
|
|
151
|
+
// (10, "Alice") - conceptually
|
|
152
|
+
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
**Encoded (AID):**
|
|
156
|
+
|
|
157
|
+
```text
|
|
158
|
+
<_0:number,_1:string>(10,"Alice")
|
|
159
|
+
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
## 🛠️ API Reference
|
|
163
|
+
|
|
164
|
+
### `encode(input: any, options?: EncodeOptions): string`
|
|
165
|
+
|
|
166
|
+
Serializes a JavaScript value into an AID string.
|
|
167
|
+
|
|
168
|
+
* `input`: The data to encode.
|
|
169
|
+
* `options`:
|
|
170
|
+
* `compact`: (boolean) Remove whitespace. Default: `true`.
|
|
171
|
+
* `colorize`: (boolean) Add ANSI colors for terminal output. Default: `false`.
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
### `decode(text: string, options?: DecodeOptions): ParseResult`
|
|
176
|
+
|
|
177
|
+
Parses an AID string.
|
|
178
|
+
|
|
179
|
+
* `text`: The AID string to parse.
|
|
180
|
+
* `options`:
|
|
181
|
+
* `debug`: (boolean) Enable detailed logging.
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
* **Returns** `ParseResult`:
|
|
185
|
+
* `node`: The parsed AST node containing value and metadata.
|
|
186
|
+
* `errors`: Array of parsing errors, if any.
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
## 📄 License
|
|
191
|
+
|
|
192
|
+
This project is licensed under the [MIT License].
|
|
193
|
+
|
|
194
|
+
---
|
|
195
|
+
|
|
196
|
+
<div align="center">
|
|
197
|
+
<sub>Built by <strong>Arkadia AI</strong>. Engineering the kernel of distributed intelligence.</sub>
|
|
198
|
+
</div>
|