brevit 0.1.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 +23 -0
- package/README.md +1237 -0
- package/TYPESCRIPT.md +230 -0
- package/example.ts +139 -0
- package/package.json +31 -0
- package/src/brevit.d.ts +212 -0
- package/src/brevit.js +589 -0
- package/test/test.js +90 -0
- package/tsconfig.json +23 -0
package/TYPESCRIPT.md
ADDED
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
# TypeScript Support for Brevit.js
|
|
2
|
+
|
|
3
|
+
Brevit.js includes comprehensive TypeScript definitions for full type safety and excellent IDE support.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
No additional installation required! TypeScript definitions are included in the package.
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install brevit-js
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Basic Usage
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
import {
|
|
17
|
+
BrevitClient,
|
|
18
|
+
BrevitConfig,
|
|
19
|
+
JsonOptimizationMode,
|
|
20
|
+
} from 'brevit-js';
|
|
21
|
+
|
|
22
|
+
const config = new BrevitConfig({
|
|
23
|
+
jsonMode: JsonOptimizationMode.Flatten,
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
const client = new BrevitClient(config);
|
|
27
|
+
const optimized = await client.optimize({ user: { name: 'John' } });
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Type Exports
|
|
31
|
+
|
|
32
|
+
All types are exported for your convenience:
|
|
33
|
+
|
|
34
|
+
### Enums
|
|
35
|
+
|
|
36
|
+
```typescript
|
|
37
|
+
import {
|
|
38
|
+
JsonOptimizationMode,
|
|
39
|
+
TextOptimizationMode,
|
|
40
|
+
ImageOptimizationMode,
|
|
41
|
+
} from 'brevit-js';
|
|
42
|
+
|
|
43
|
+
// Usage
|
|
44
|
+
const mode: typeof JsonOptimizationMode.Flatten = JsonOptimizationMode.Flatten;
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### Type Aliases
|
|
48
|
+
|
|
49
|
+
```typescript
|
|
50
|
+
import type {
|
|
51
|
+
JsonOptimizationModeType,
|
|
52
|
+
TextOptimizationModeType,
|
|
53
|
+
ImageOptimizationModeType,
|
|
54
|
+
} from 'brevit-js';
|
|
55
|
+
|
|
56
|
+
function setMode(mode: JsonOptimizationModeType) {
|
|
57
|
+
// Type-safe mode setting
|
|
58
|
+
}
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### Interfaces
|
|
62
|
+
|
|
63
|
+
```typescript
|
|
64
|
+
import type {
|
|
65
|
+
BrevitConfigOptions,
|
|
66
|
+
BrevitClientOptions,
|
|
67
|
+
TextOptimizerFunction,
|
|
68
|
+
ImageOptimizerFunction,
|
|
69
|
+
} from 'brevit-js';
|
|
70
|
+
|
|
71
|
+
// Configuration options
|
|
72
|
+
const config: BrevitConfigOptions = {
|
|
73
|
+
jsonMode: JsonOptimizationMode.Flatten,
|
|
74
|
+
longTextThreshold: 1000,
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
// Custom optimizer functions
|
|
78
|
+
const textOptimizer: TextOptimizerFunction = async (text, intent) => {
|
|
79
|
+
// Your implementation
|
|
80
|
+
return optimizedText;
|
|
81
|
+
};
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
## Examples
|
|
85
|
+
|
|
86
|
+
### Example 1: Type-Safe Configuration
|
|
87
|
+
|
|
88
|
+
```typescript
|
|
89
|
+
import {
|
|
90
|
+
BrevitClient,
|
|
91
|
+
BrevitConfig,
|
|
92
|
+
JsonOptimizationMode,
|
|
93
|
+
type BrevitConfigOptions,
|
|
94
|
+
} from 'brevit-js';
|
|
95
|
+
|
|
96
|
+
const configOptions: BrevitConfigOptions = {
|
|
97
|
+
jsonMode: JsonOptimizationMode.Flatten,
|
|
98
|
+
textMode: 'Clean',
|
|
99
|
+
imageMode: 'Ocr',
|
|
100
|
+
jsonPathsToKeep: ['user.name', 'order.orderId'],
|
|
101
|
+
longTextThreshold: 1000,
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
const config = new BrevitConfig(configOptions);
|
|
105
|
+
const client = new BrevitClient(config);
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
### Example 2: Custom Optimizers with Types
|
|
109
|
+
|
|
110
|
+
```typescript
|
|
111
|
+
import {
|
|
112
|
+
BrevitClient,
|
|
113
|
+
BrevitConfig,
|
|
114
|
+
type TextOptimizerFunction,
|
|
115
|
+
type ImageOptimizerFunction,
|
|
116
|
+
} from 'brevit-js';
|
|
117
|
+
|
|
118
|
+
const customTextOptimizer: TextOptimizerFunction = async (longText, intent) => {
|
|
119
|
+
const response = await fetch('/api/summarize', {
|
|
120
|
+
method: 'POST',
|
|
121
|
+
headers: { 'Content-Type': 'application/json' },
|
|
122
|
+
body: JSON.stringify({ text: longText, intent }),
|
|
123
|
+
});
|
|
124
|
+
const { summary } = await response.json();
|
|
125
|
+
return summary;
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
const customImageOptimizer: ImageOptimizerFunction = async (imageData, intent) => {
|
|
129
|
+
const base64 = btoa(String.fromCharCode(...new Uint8Array(imageData)));
|
|
130
|
+
const response = await fetch('/api/ocr', {
|
|
131
|
+
method: 'POST',
|
|
132
|
+
headers: { 'Content-Type': 'application/json' },
|
|
133
|
+
body: JSON.stringify({ image: base64 }),
|
|
134
|
+
});
|
|
135
|
+
const { text } = await response.json();
|
|
136
|
+
return text;
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
const client = new BrevitClient(new BrevitConfig(), {
|
|
140
|
+
textOptimizer: customTextOptimizer,
|
|
141
|
+
imageOptimizer: customImageOptimizer,
|
|
142
|
+
});
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
### Example 3: Type-Safe Data Structures
|
|
146
|
+
|
|
147
|
+
```typescript
|
|
148
|
+
interface User {
|
|
149
|
+
id: string;
|
|
150
|
+
name: string;
|
|
151
|
+
email: string;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
interface Order {
|
|
155
|
+
orderId: string;
|
|
156
|
+
status: string;
|
|
157
|
+
items: Array<{
|
|
158
|
+
sku: string;
|
|
159
|
+
name: string;
|
|
160
|
+
quantity: number;
|
|
161
|
+
}>;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
const user: User = {
|
|
165
|
+
id: 'u-123',
|
|
166
|
+
name: 'Javian',
|
|
167
|
+
email: 'support@javianpicardo.com',
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
const order: Order = {
|
|
171
|
+
orderId: 'o-456',
|
|
172
|
+
status: 'SHIPPED',
|
|
173
|
+
items: [
|
|
174
|
+
{ sku: 'A-88', name: 'Brevit Pro License', quantity: 1 },
|
|
175
|
+
],
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
const client = new BrevitClient();
|
|
179
|
+
const optimizedUser = await client.optimize(user);
|
|
180
|
+
const optimizedOrder = await client.optimize(order);
|
|
181
|
+
// Both return Promise<string>
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
### Example 4: Generic Helper Function
|
|
185
|
+
|
|
186
|
+
```typescript
|
|
187
|
+
import { BrevitClient, BrevitConfig } from 'brevit-js';
|
|
188
|
+
|
|
189
|
+
async function optimizeData<T>(data: T): Promise<string> {
|
|
190
|
+
const client = new BrevitClient();
|
|
191
|
+
return await client.optimize(data);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
const result = await optimizeData({ name: 'John', age: 30 });
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
## IDE Support
|
|
198
|
+
|
|
199
|
+
With TypeScript definitions, you get:
|
|
200
|
+
|
|
201
|
+
- ✅ **Autocomplete**: Full IntelliSense support in VS Code, WebStorm, etc.
|
|
202
|
+
- ✅ **Type Checking**: Catch errors at compile time
|
|
203
|
+
- ✅ **Refactoring**: Safe refactoring with type-aware tools
|
|
204
|
+
- ✅ **Documentation**: Hover to see JSDoc comments
|
|
205
|
+
- ✅ **Navigation**: Jump to definitions and find references
|
|
206
|
+
|
|
207
|
+
## Type Checking
|
|
208
|
+
|
|
209
|
+
Enable strict type checking in your `tsconfig.json`:
|
|
210
|
+
|
|
211
|
+
```json
|
|
212
|
+
{
|
|
213
|
+
"compilerOptions": {
|
|
214
|
+
"strict": true,
|
|
215
|
+
"noImplicitAny": true,
|
|
216
|
+
"strictNullChecks": true
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
## Compatibility
|
|
222
|
+
|
|
223
|
+
- **TypeScript**: 4.5+
|
|
224
|
+
- **Node.js**: 18.x, 20.x
|
|
225
|
+
- **Browsers**: Modern browsers with ES2020 support
|
|
226
|
+
|
|
227
|
+
## Contributing
|
|
228
|
+
|
|
229
|
+
When contributing to Brevit.js, ensure TypeScript definitions stay in sync with the JavaScript implementation. The definitions file is located at `src/brevit.d.ts`.
|
|
230
|
+
|
package/example.ts
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TypeScript usage example for Brevit.js
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
BrevitClient,
|
|
7
|
+
BrevitConfig,
|
|
8
|
+
JsonOptimizationMode,
|
|
9
|
+
TextOptimizationMode,
|
|
10
|
+
ImageOptimizationMode,
|
|
11
|
+
type BrevitConfigOptions,
|
|
12
|
+
type TextOptimizerFunction,
|
|
13
|
+
type ImageOptimizerFunction,
|
|
14
|
+
} from './src/brevit.js';
|
|
15
|
+
|
|
16
|
+
// Example 1: Basic usage with default configuration
|
|
17
|
+
async function example1() {
|
|
18
|
+
const client = new BrevitClient();
|
|
19
|
+
|
|
20
|
+
const data = {
|
|
21
|
+
user: {
|
|
22
|
+
name: 'Javian',
|
|
23
|
+
email: 'support@javianpicardo.com',
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const optimized = await client.optimize(data);
|
|
28
|
+
console.log(optimized);
|
|
29
|
+
// Output:
|
|
30
|
+
// user.name: Javian
|
|
31
|
+
// user.email: support@javianpicardo.com
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Example 2: Custom configuration
|
|
35
|
+
async function example2() {
|
|
36
|
+
const config: BrevitConfigOptions = {
|
|
37
|
+
jsonMode: JsonOptimizationMode.Flatten,
|
|
38
|
+
textMode: TextOptimizationMode.Clean,
|
|
39
|
+
imageMode: ImageOptimizationMode.Ocr,
|
|
40
|
+
longTextThreshold: 1000,
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const client = new BrevitClient(new BrevitConfig(config));
|
|
44
|
+
|
|
45
|
+
const jsonString = '{"order": {"orderId": "o-456", "status": "SHIPPED"}}';
|
|
46
|
+
const optimized = await client.optimize(jsonString);
|
|
47
|
+
console.log(optimized);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Example 3: Custom text optimizer
|
|
51
|
+
async function example3() {
|
|
52
|
+
const customTextOptimizer: TextOptimizerFunction = async (longText, intent) => {
|
|
53
|
+
// Call your backend API for summarization
|
|
54
|
+
const response = await fetch('/api/summarize', {
|
|
55
|
+
method: 'POST',
|
|
56
|
+
headers: { 'Content-Type': 'application/json' },
|
|
57
|
+
body: JSON.stringify({ text: longText, intent }),
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
const { summary } = await response.json();
|
|
61
|
+
return summary;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
const config = new BrevitConfig({
|
|
65
|
+
textMode: TextOptimizationMode.SummarizeFast,
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
const client = new BrevitClient(config, {
|
|
69
|
+
textOptimizer: customTextOptimizer,
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
const longText = '...very long text...';
|
|
73
|
+
const optimized = await client.optimize(longText);
|
|
74
|
+
console.log(optimized);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// Example 4: Custom image optimizer
|
|
78
|
+
async function example4() {
|
|
79
|
+
const customImageOptimizer: ImageOptimizerFunction = async (imageData, intent) => {
|
|
80
|
+
// Convert ArrayBuffer to base64 if needed
|
|
81
|
+
const base64 = btoa(
|
|
82
|
+
String.fromCharCode(...new Uint8Array(imageData))
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
// Call your backend OCR API
|
|
86
|
+
const response = await fetch('/api/ocr', {
|
|
87
|
+
method: 'POST',
|
|
88
|
+
headers: { 'Content-Type': 'application/json' },
|
|
89
|
+
body: JSON.stringify({ image: base64 }),
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
const { text } = await response.json();
|
|
93
|
+
return text;
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
const config = new BrevitConfig({
|
|
97
|
+
imageMode: ImageOptimizationMode.Ocr,
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
const client = new BrevitClient(config, {
|
|
101
|
+
imageOptimizer: customImageOptimizer,
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
const imageData = await fetch('receipt.jpg').then((r) => r.arrayBuffer());
|
|
105
|
+
const optimized = await client.optimize(imageData);
|
|
106
|
+
console.log(optimized);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// Example 5: Type-safe usage with interfaces
|
|
110
|
+
interface Order {
|
|
111
|
+
orderId: string;
|
|
112
|
+
status: string;
|
|
113
|
+
items: Array<{
|
|
114
|
+
sku: string;
|
|
115
|
+
name: string;
|
|
116
|
+
quantity: number;
|
|
117
|
+
}>;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
async function example5() {
|
|
121
|
+
const client = new BrevitClient();
|
|
122
|
+
|
|
123
|
+
const order: Order = {
|
|
124
|
+
orderId: 'o-456',
|
|
125
|
+
status: 'SHIPPED',
|
|
126
|
+
items: [
|
|
127
|
+
{ sku: 'A-88', name: 'Brevit Pro License', quantity: 1 },
|
|
128
|
+
],
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
const optimized = await client.optimize(order);
|
|
132
|
+
console.log(optimized);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// Run examples
|
|
136
|
+
if (import.meta.url === `file://${process.argv[1]}`) {
|
|
137
|
+
example1().catch(console.error);
|
|
138
|
+
}
|
|
139
|
+
|
package/package.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "brevit",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "A high-performance JavaScript library for semantically compressing and optimizing data before sending it to a Large Language Model (LLM).",
|
|
5
|
+
"main": "src/brevit.js",
|
|
6
|
+
"types": "src/brevit.d.ts",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"test": "node test/test.js",
|
|
10
|
+
"build": "echo 'No build step required for ES modules'"
|
|
11
|
+
},
|
|
12
|
+
"keywords": [
|
|
13
|
+
"llm",
|
|
14
|
+
"token-optimization",
|
|
15
|
+
"json-compression",
|
|
16
|
+
"ai",
|
|
17
|
+
"semantic-compression"
|
|
18
|
+
],
|
|
19
|
+
"author": {
|
|
20
|
+
"name": "JavianDev",
|
|
21
|
+
"email": "support@javianpicardo.com"
|
|
22
|
+
},
|
|
23
|
+
"license": "MIT",
|
|
24
|
+
"repository": {
|
|
25
|
+
"type": "git",
|
|
26
|
+
"url": "https://github.com/JavianDev/Brevit.js.git"
|
|
27
|
+
},
|
|
28
|
+
"optionalDependencies": {
|
|
29
|
+
"js-yaml": "^4.1.0"
|
|
30
|
+
}
|
|
31
|
+
}
|
package/src/brevit.d.ts
ADDED
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Brevit.js - TypeScript Definitions
|
|
3
|
+
* A high-performance JavaScript library for semantically compressing
|
|
4
|
+
* and optimizing data before sending it to a Large Language Model (LLM).
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* JSON optimization modes
|
|
9
|
+
*/
|
|
10
|
+
export const JsonOptimizationMode: {
|
|
11
|
+
readonly None: 'None';
|
|
12
|
+
readonly Flatten: 'Flatten';
|
|
13
|
+
readonly ToYaml: 'ToYaml';
|
|
14
|
+
readonly Filter: 'Filter';
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Text optimization modes
|
|
19
|
+
*/
|
|
20
|
+
export const TextOptimizationMode: {
|
|
21
|
+
readonly None: 'None';
|
|
22
|
+
readonly Clean: 'Clean';
|
|
23
|
+
readonly SummarizeFast: 'SummarizeFast';
|
|
24
|
+
readonly SummarizeHighQuality: 'SummarizeHighQuality';
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Image optimization modes
|
|
29
|
+
*/
|
|
30
|
+
export const ImageOptimizationMode: {
|
|
31
|
+
readonly None: 'None';
|
|
32
|
+
readonly Ocr: 'Ocr';
|
|
33
|
+
readonly Metadata: 'Metadata';
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Type for JSON optimization mode values
|
|
38
|
+
*/
|
|
39
|
+
export type JsonOptimizationModeType = typeof JsonOptimizationMode[keyof typeof JsonOptimizationMode];
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Type for text optimization mode values
|
|
43
|
+
*/
|
|
44
|
+
export type TextOptimizationModeType = typeof TextOptimizationMode[keyof typeof TextOptimizationMode];
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Type for image optimization mode values
|
|
48
|
+
*/
|
|
49
|
+
export type ImageOptimizationModeType = typeof ImageOptimizationMode[keyof typeof ImageOptimizationMode];
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Configuration options for BrevitClient
|
|
53
|
+
*/
|
|
54
|
+
export interface BrevitConfigOptions {
|
|
55
|
+
/**
|
|
56
|
+
* Strategy for JSON optimization
|
|
57
|
+
* @default JsonOptimizationMode.Flatten
|
|
58
|
+
*/
|
|
59
|
+
jsonMode?: JsonOptimizationModeType;
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Strategy for text optimization
|
|
63
|
+
* @default TextOptimizationMode.Clean
|
|
64
|
+
*/
|
|
65
|
+
textMode?: TextOptimizationModeType;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Strategy for image optimization
|
|
69
|
+
* @default ImageOptimizationMode.Ocr
|
|
70
|
+
*/
|
|
71
|
+
imageMode?: ImageOptimizationModeType;
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* JSON property paths to keep when using Filter mode
|
|
75
|
+
* @default []
|
|
76
|
+
*/
|
|
77
|
+
jsonPathsToKeep?: string[];
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Character count threshold to trigger text optimization
|
|
81
|
+
* @default 500
|
|
82
|
+
*/
|
|
83
|
+
longTextThreshold?: number;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Configuration object for the BrevitClient
|
|
88
|
+
*/
|
|
89
|
+
export class BrevitConfig {
|
|
90
|
+
/**
|
|
91
|
+
* JSON optimization mode
|
|
92
|
+
*/
|
|
93
|
+
jsonMode: JsonOptimizationModeType;
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Text optimization mode
|
|
97
|
+
*/
|
|
98
|
+
textMode: TextOptimizationModeType;
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Image optimization mode
|
|
102
|
+
*/
|
|
103
|
+
imageMode: ImageOptimizationModeType;
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* JSON paths to keep for Filter mode
|
|
107
|
+
*/
|
|
108
|
+
jsonPathsToKeep: string[];
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Long text threshold
|
|
112
|
+
*/
|
|
113
|
+
longTextThreshold: number;
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Creates a new BrevitConfig instance
|
|
117
|
+
* @param options Configuration options
|
|
118
|
+
*/
|
|
119
|
+
constructor(options?: BrevitConfigOptions);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Custom text optimizer function signature
|
|
124
|
+
* @param longText The text to optimize
|
|
125
|
+
* @param intent Optional hint about the user's goal
|
|
126
|
+
* @returns Promise resolving to optimized text
|
|
127
|
+
*/
|
|
128
|
+
export type TextOptimizerFunction = (longText: string, intent?: string | null) => Promise<string>;
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Custom image optimizer function signature
|
|
132
|
+
* @param imageData The image data (ArrayBuffer, Uint8Array, or Buffer)
|
|
133
|
+
* @param intent Optional hint about the user's goal
|
|
134
|
+
* @returns Promise resolving to optimized text representation
|
|
135
|
+
*/
|
|
136
|
+
export type ImageOptimizerFunction = (
|
|
137
|
+
imageData: ArrayBuffer | Uint8Array | Buffer,
|
|
138
|
+
intent?: string | null
|
|
139
|
+
) => Promise<string>;
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Options for BrevitClient constructor
|
|
143
|
+
*/
|
|
144
|
+
export interface BrevitClientOptions {
|
|
145
|
+
/**
|
|
146
|
+
* Custom text optimizer function
|
|
147
|
+
*/
|
|
148
|
+
textOptimizer?: TextOptimizerFunction;
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Custom image optimizer function
|
|
152
|
+
*/
|
|
153
|
+
imageOptimizer?: ImageOptimizerFunction;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* The main client for the Brevit.js library.
|
|
158
|
+
* This class orchestrates the optimization pipeline.
|
|
159
|
+
*/
|
|
160
|
+
export class BrevitClient {
|
|
161
|
+
/**
|
|
162
|
+
* Creates a new BrevitClient instance
|
|
163
|
+
* @param config Brevit configuration (defaults to new BrevitConfig())
|
|
164
|
+
* @param options Optional custom optimizers
|
|
165
|
+
*/
|
|
166
|
+
constructor(config?: BrevitConfig, options?: BrevitClientOptions);
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* The primary method. Optimizes any JS object, JSON string,
|
|
170
|
+
* or data (text, image bytes) into a token-efficient string.
|
|
171
|
+
*
|
|
172
|
+
* @param rawData The data to optimize. Can be:
|
|
173
|
+
* - A plain JavaScript object
|
|
174
|
+
* - A JSON string
|
|
175
|
+
* - A text string
|
|
176
|
+
* - An ArrayBuffer, Uint8Array, or Buffer (for images)
|
|
177
|
+
* - Any other primitive value
|
|
178
|
+
* @param intent Optional hint about the user's goal, which can
|
|
179
|
+
* help the optimizers make better decisions
|
|
180
|
+
* @returns Promise resolving to an optimized string
|
|
181
|
+
*
|
|
182
|
+
* @example
|
|
183
|
+
* ```typescript
|
|
184
|
+
* const client = new BrevitClient();
|
|
185
|
+
* const optimized = await client.optimize({ user: { name: "John" } });
|
|
186
|
+
* // Returns: "user.name: John"
|
|
187
|
+
* ```
|
|
188
|
+
*
|
|
189
|
+
* @example
|
|
190
|
+
* ```typescript
|
|
191
|
+
* const optimized = await client.optimize('{"order": {"id": "123"}}');
|
|
192
|
+
* // Returns: "order.id: 123"
|
|
193
|
+
* ```
|
|
194
|
+
*
|
|
195
|
+
* @example
|
|
196
|
+
* ```typescript
|
|
197
|
+
* const imageData = await fetch('image.jpg').then(r => r.arrayBuffer());
|
|
198
|
+
* const optimized = await client.optimize(imageData);
|
|
199
|
+
* // Returns OCR text or metadata
|
|
200
|
+
* ```
|
|
201
|
+
*/
|
|
202
|
+
optimize(rawData: unknown, intent?: string | null): Promise<string>;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
// Re-export types for convenience
|
|
206
|
+
export type {
|
|
207
|
+
BrevitConfigOptions,
|
|
208
|
+
BrevitClientOptions,
|
|
209
|
+
TextOptimizerFunction,
|
|
210
|
+
ImageOptimizerFunction,
|
|
211
|
+
};
|
|
212
|
+
|