@goreal-ai/echo-pdk 0.1.0
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/dist/ai-judge/index.d.ts +177 -0
- package/dist/ai-judge/index.d.ts.map +1 -0
- package/dist/ai-judge/index.js +299 -0
- package/dist/ai-judge/index.js.map +1 -0
- package/dist/evaluator/evaluator.d.ts +136 -0
- package/dist/evaluator/evaluator.d.ts.map +1 -0
- package/dist/evaluator/evaluator.js +407 -0
- package/dist/evaluator/evaluator.js.map +1 -0
- package/dist/evaluator/index.d.ts +7 -0
- package/dist/evaluator/index.d.ts.map +1 -0
- package/dist/evaluator/index.js +8 -0
- package/dist/evaluator/index.js.map +1 -0
- package/dist/evaluator/operators.d.ts +105 -0
- package/dist/evaluator/operators.d.ts.map +1 -0
- package/dist/evaluator/operators.js +371 -0
- package/dist/evaluator/operators.js.map +1 -0
- package/dist/index.d.ts +115 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +388 -0
- package/dist/index.js.map +1 -0
- package/dist/parser/ast.d.ts +106 -0
- package/dist/parser/ast.d.ts.map +1 -0
- package/dist/parser/ast.js +260 -0
- package/dist/parser/ast.js.map +1 -0
- package/dist/parser/index.d.ts +8 -0
- package/dist/parser/index.d.ts.map +1 -0
- package/dist/parser/index.js +13 -0
- package/dist/parser/index.js.map +1 -0
- package/dist/parser/lexer.d.ts +199 -0
- package/dist/parser/lexer.d.ts.map +1 -0
- package/dist/parser/lexer.js +491 -0
- package/dist/parser/lexer.js.map +1 -0
- package/dist/parser/parser.d.ts +49 -0
- package/dist/parser/parser.d.ts.map +1 -0
- package/dist/parser/parser.js +615 -0
- package/dist/parser/parser.js.map +1 -0
- package/dist/plugins/index.d.ts +62 -0
- package/dist/plugins/index.d.ts.map +1 -0
- package/dist/plugins/index.js +170 -0
- package/dist/plugins/index.js.map +1 -0
- package/dist/renderer/index.d.ts +6 -0
- package/dist/renderer/index.d.ts.map +1 -0
- package/dist/renderer/index.js +5 -0
- package/dist/renderer/index.js.map +1 -0
- package/dist/renderer/renderer.d.ts +97 -0
- package/dist/renderer/renderer.d.ts.map +1 -0
- package/dist/renderer/renderer.js +243 -0
- package/dist/renderer/renderer.js.map +1 -0
- package/dist/types.d.ts +255 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +9 -0
- package/dist/types.js.map +1 -0
- package/package.json +54 -0
|
@@ -0,0 +1,371 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Built-in Operators for Echo DSL
|
|
3
|
+
*
|
|
4
|
+
* This file implements all built-in operators for the Echo DSL.
|
|
5
|
+
* Operators are used in conditions: [#IF {{var}} #operator(arg)]
|
|
6
|
+
*
|
|
7
|
+
* IMPLEMENTATION GUIDE:
|
|
8
|
+
*
|
|
9
|
+
* Each operator is a function that:
|
|
10
|
+
* - Takes a value (the variable being tested)
|
|
11
|
+
* - Takes an optional argument (the operator parameter)
|
|
12
|
+
* - Returns a boolean (or Promise<boolean> for async operators)
|
|
13
|
+
*
|
|
14
|
+
* BUILT-IN OPERATORS:
|
|
15
|
+
* - #equals(value) - Exact equality
|
|
16
|
+
* - #contains(value) - String/array contains
|
|
17
|
+
* - #exists - Value is defined and not empty
|
|
18
|
+
* - #matches(regex) - Regex pattern match
|
|
19
|
+
* - #gt(n), #lt(n) - Greater than, less than
|
|
20
|
+
* - #gte(n), #lte(n) - Greater/less than or equal
|
|
21
|
+
* - #in(a,b,c) - Value is in list
|
|
22
|
+
* - #ai_judge(question) - LLM-evaluated condition
|
|
23
|
+
*/
|
|
24
|
+
// =============================================================================
|
|
25
|
+
// COMPARISON OPERATORS
|
|
26
|
+
// =============================================================================
|
|
27
|
+
/**
|
|
28
|
+
* #equals - Exact equality check
|
|
29
|
+
*
|
|
30
|
+
* @example {{genre}} #equals(Horror)
|
|
31
|
+
*/
|
|
32
|
+
export const equalsOperator = {
|
|
33
|
+
type: 'comparison',
|
|
34
|
+
description: 'Exact equality check',
|
|
35
|
+
example: '{{genre}} #equals(Horror)',
|
|
36
|
+
autocomplete: {
|
|
37
|
+
trigger: '#eq',
|
|
38
|
+
snippet: '#equals($1)',
|
|
39
|
+
},
|
|
40
|
+
handler: (value, argument) => {
|
|
41
|
+
// Handle string comparison (case-insensitive by default)
|
|
42
|
+
if (typeof value === 'string' && typeof argument === 'string') {
|
|
43
|
+
return value.toLowerCase() === argument.toLowerCase();
|
|
44
|
+
}
|
|
45
|
+
// Strict equality for other types
|
|
46
|
+
return value === argument;
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
/**
|
|
50
|
+
* #contains - Check if string/array contains a value
|
|
51
|
+
*
|
|
52
|
+
* @example {{companions}} #contains(Shimon)
|
|
53
|
+
*/
|
|
54
|
+
export const containsOperator = {
|
|
55
|
+
type: 'comparison',
|
|
56
|
+
description: 'Check if string or array contains value',
|
|
57
|
+
example: '{{companions}} #contains(Shimon)',
|
|
58
|
+
autocomplete: {
|
|
59
|
+
trigger: '#con',
|
|
60
|
+
snippet: '#contains($1)',
|
|
61
|
+
},
|
|
62
|
+
handler: (value, argument) => {
|
|
63
|
+
if (typeof value === 'string' && typeof argument === 'string') {
|
|
64
|
+
return value.toLowerCase().includes(argument.toLowerCase());
|
|
65
|
+
}
|
|
66
|
+
if (Array.isArray(value)) {
|
|
67
|
+
return value.some((item) => {
|
|
68
|
+
if (typeof item === 'string' && typeof argument === 'string') {
|
|
69
|
+
return item.toLowerCase() === argument.toLowerCase();
|
|
70
|
+
}
|
|
71
|
+
return item === argument;
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
return false;
|
|
75
|
+
},
|
|
76
|
+
};
|
|
77
|
+
/**
|
|
78
|
+
* #exists - Check if value is defined and not empty
|
|
79
|
+
*
|
|
80
|
+
* @example {{user.preferences}} #exists
|
|
81
|
+
*/
|
|
82
|
+
export const existsOperator = {
|
|
83
|
+
type: 'unary',
|
|
84
|
+
description: 'Check if variable is defined and not empty',
|
|
85
|
+
example: '{{user.preferences}} #exists',
|
|
86
|
+
autocomplete: {
|
|
87
|
+
trigger: '#ex',
|
|
88
|
+
snippet: '#exists',
|
|
89
|
+
},
|
|
90
|
+
handler: (value) => {
|
|
91
|
+
if (value === undefined || value === null)
|
|
92
|
+
return false;
|
|
93
|
+
if (typeof value === 'string')
|
|
94
|
+
return value.length > 0;
|
|
95
|
+
if (Array.isArray(value))
|
|
96
|
+
return value.length > 0;
|
|
97
|
+
if (typeof value === 'object')
|
|
98
|
+
return Object.keys(value).length > 0;
|
|
99
|
+
return true;
|
|
100
|
+
},
|
|
101
|
+
};
|
|
102
|
+
/**
|
|
103
|
+
* #matches - Regex pattern match
|
|
104
|
+
*
|
|
105
|
+
* @example {{email}} #matches(.*@.*)
|
|
106
|
+
*/
|
|
107
|
+
export const matchesOperator = {
|
|
108
|
+
type: 'comparison',
|
|
109
|
+
description: 'Regex pattern matching',
|
|
110
|
+
example: '{{email}} #matches(.*@.*)',
|
|
111
|
+
autocomplete: {
|
|
112
|
+
trigger: '#mat',
|
|
113
|
+
snippet: '#matches($1)',
|
|
114
|
+
},
|
|
115
|
+
handler: (value, pattern) => {
|
|
116
|
+
if (typeof value !== 'string' || typeof pattern !== 'string') {
|
|
117
|
+
return false;
|
|
118
|
+
}
|
|
119
|
+
try {
|
|
120
|
+
const regex = new RegExp(pattern);
|
|
121
|
+
return regex.test(value);
|
|
122
|
+
}
|
|
123
|
+
catch {
|
|
124
|
+
// Invalid regex pattern
|
|
125
|
+
return false;
|
|
126
|
+
}
|
|
127
|
+
},
|
|
128
|
+
};
|
|
129
|
+
// =============================================================================
|
|
130
|
+
// NUMERIC OPERATORS
|
|
131
|
+
// =============================================================================
|
|
132
|
+
/**
|
|
133
|
+
* #greater_than - Greater than (alias: #gt)
|
|
134
|
+
*
|
|
135
|
+
* @example {{age}} #greater_than(18)
|
|
136
|
+
*/
|
|
137
|
+
export const gtOperator = {
|
|
138
|
+
type: 'comparison',
|
|
139
|
+
description: 'Greater than comparison',
|
|
140
|
+
example: '{{age}} #greater_than(18)',
|
|
141
|
+
autocomplete: {
|
|
142
|
+
trigger: '#greater',
|
|
143
|
+
snippet: '#greater_than($1)',
|
|
144
|
+
},
|
|
145
|
+
handler: (value, threshold) => {
|
|
146
|
+
const num = typeof value === 'string' ? parseFloat(value) : value;
|
|
147
|
+
const thresh = typeof threshold === 'string' ? parseFloat(threshold) : threshold;
|
|
148
|
+
if (typeof num !== 'number' || typeof thresh !== 'number')
|
|
149
|
+
return false;
|
|
150
|
+
if (isNaN(num) || isNaN(thresh))
|
|
151
|
+
return false;
|
|
152
|
+
return num > thresh;
|
|
153
|
+
},
|
|
154
|
+
};
|
|
155
|
+
/**
|
|
156
|
+
* #greater_than_or_equal - Greater than or equal (alias: #gte)
|
|
157
|
+
*/
|
|
158
|
+
export const gteOperator = {
|
|
159
|
+
type: 'comparison',
|
|
160
|
+
description: 'Greater than or equal comparison',
|
|
161
|
+
example: '{{age}} #greater_than_or_equal(18)',
|
|
162
|
+
autocomplete: {
|
|
163
|
+
trigger: '#greater_than_or',
|
|
164
|
+
snippet: '#greater_than_or_equal($1)',
|
|
165
|
+
},
|
|
166
|
+
handler: (value, threshold) => {
|
|
167
|
+
const num = typeof value === 'string' ? parseFloat(value) : value;
|
|
168
|
+
const thresh = typeof threshold === 'string' ? parseFloat(threshold) : threshold;
|
|
169
|
+
if (typeof num !== 'number' || typeof thresh !== 'number')
|
|
170
|
+
return false;
|
|
171
|
+
if (isNaN(num) || isNaN(thresh))
|
|
172
|
+
return false;
|
|
173
|
+
return num >= thresh;
|
|
174
|
+
},
|
|
175
|
+
};
|
|
176
|
+
/**
|
|
177
|
+
* #less_than - Less than (alias: #lt)
|
|
178
|
+
*/
|
|
179
|
+
export const ltOperator = {
|
|
180
|
+
type: 'comparison',
|
|
181
|
+
description: 'Less than comparison',
|
|
182
|
+
example: '{{count}} #less_than(10)',
|
|
183
|
+
autocomplete: {
|
|
184
|
+
trigger: '#less',
|
|
185
|
+
snippet: '#less_than($1)',
|
|
186
|
+
},
|
|
187
|
+
handler: (value, threshold) => {
|
|
188
|
+
const num = typeof value === 'string' ? parseFloat(value) : value;
|
|
189
|
+
const thresh = typeof threshold === 'string' ? parseFloat(threshold) : threshold;
|
|
190
|
+
if (typeof num !== 'number' || typeof thresh !== 'number')
|
|
191
|
+
return false;
|
|
192
|
+
if (isNaN(num) || isNaN(thresh))
|
|
193
|
+
return false;
|
|
194
|
+
return num < thresh;
|
|
195
|
+
},
|
|
196
|
+
};
|
|
197
|
+
/**
|
|
198
|
+
* #less_than_or_equal - Less than or equal (alias: #lte)
|
|
199
|
+
*/
|
|
200
|
+
export const lteOperator = {
|
|
201
|
+
type: 'comparison',
|
|
202
|
+
description: 'Less than or equal comparison',
|
|
203
|
+
example: '{{count}} #less_than_or_equal(10)',
|
|
204
|
+
autocomplete: {
|
|
205
|
+
trigger: '#less_than_or',
|
|
206
|
+
snippet: '#less_than_or_equal($1)',
|
|
207
|
+
},
|
|
208
|
+
handler: (value, threshold) => {
|
|
209
|
+
const num = typeof value === 'string' ? parseFloat(value) : value;
|
|
210
|
+
const thresh = typeof threshold === 'string' ? parseFloat(threshold) : threshold;
|
|
211
|
+
if (typeof num !== 'number' || typeof thresh !== 'number')
|
|
212
|
+
return false;
|
|
213
|
+
if (isNaN(num) || isNaN(thresh))
|
|
214
|
+
return false;
|
|
215
|
+
return num <= thresh;
|
|
216
|
+
},
|
|
217
|
+
};
|
|
218
|
+
// =============================================================================
|
|
219
|
+
// LIST OPERATORS
|
|
220
|
+
// =============================================================================
|
|
221
|
+
/**
|
|
222
|
+
* #one_of - Check if value is in a list (alias: #in)
|
|
223
|
+
*
|
|
224
|
+
* @example {{status}} #one_of(active,pending,completed)
|
|
225
|
+
*/
|
|
226
|
+
export const inOperator = {
|
|
227
|
+
type: 'comparison',
|
|
228
|
+
description: 'Check if value is one of the given options',
|
|
229
|
+
example: '{{status}} #one_of(active,pending,completed)',
|
|
230
|
+
autocomplete: {
|
|
231
|
+
trigger: '#one',
|
|
232
|
+
snippet: '#one_of($1)',
|
|
233
|
+
},
|
|
234
|
+
handler: (value, list) => {
|
|
235
|
+
// List can be passed as array or comma-separated string
|
|
236
|
+
let items;
|
|
237
|
+
if (Array.isArray(list)) {
|
|
238
|
+
items = list;
|
|
239
|
+
}
|
|
240
|
+
else if (typeof list === 'string') {
|
|
241
|
+
items = list.split(',').map((s) => s.trim());
|
|
242
|
+
}
|
|
243
|
+
else {
|
|
244
|
+
return false;
|
|
245
|
+
}
|
|
246
|
+
// Check if value is in list
|
|
247
|
+
const valueStr = String(value).toLowerCase();
|
|
248
|
+
return items.some((item) => String(item).toLowerCase() === valueStr);
|
|
249
|
+
},
|
|
250
|
+
};
|
|
251
|
+
// =============================================================================
|
|
252
|
+
// AI OPERATOR (ASYNC)
|
|
253
|
+
// =============================================================================
|
|
254
|
+
/**
|
|
255
|
+
* #ai_judge - LLM-evaluated boolean condition
|
|
256
|
+
*
|
|
257
|
+
* This operator queries an LLM to evaluate a boolean condition.
|
|
258
|
+
* It's async and results are cached for performance.
|
|
259
|
+
*
|
|
260
|
+
* @example {{content}} #ai_judge(Is this appropriate for children?)
|
|
261
|
+
*/
|
|
262
|
+
export const aiJudgeOperator = {
|
|
263
|
+
type: 'ai',
|
|
264
|
+
description: 'LLM-evaluated boolean condition',
|
|
265
|
+
example: '{{content}} #ai_judge(Is this appropriate for children?)',
|
|
266
|
+
autocomplete: {
|
|
267
|
+
trigger: '#ai',
|
|
268
|
+
snippet: '#ai_judge($1)',
|
|
269
|
+
},
|
|
270
|
+
handler: async (_value, _question) => {
|
|
271
|
+
// TODO: Implement AI judge
|
|
272
|
+
//
|
|
273
|
+
// IMPLEMENTATION STEPS:
|
|
274
|
+
// 1. Get the AI provider from context (passed via closure or config)
|
|
275
|
+
// 2. Construct prompt asking for yes/no answer
|
|
276
|
+
// 3. Call the AI provider
|
|
277
|
+
// 4. Parse response as boolean
|
|
278
|
+
// 5. Cache result for identical value+question combinations
|
|
279
|
+
//
|
|
280
|
+
// PROMPT TEMPLATE:
|
|
281
|
+
// "Given the following value: {value}
|
|
282
|
+
// Answer this question with only 'yes' or 'no':
|
|
283
|
+
// {question}"
|
|
284
|
+
//
|
|
285
|
+
// CACHING:
|
|
286
|
+
// Cache key = hash(value + question)
|
|
287
|
+
// Cache should be per-render to avoid stale data across renders
|
|
288
|
+
throw new Error('AI Judge not implemented. Configure aiProvider in EchoConfig.');
|
|
289
|
+
},
|
|
290
|
+
};
|
|
291
|
+
// =============================================================================
|
|
292
|
+
// OPERATOR REGISTRY
|
|
293
|
+
// =============================================================================
|
|
294
|
+
/**
|
|
295
|
+
* All built-in operators.
|
|
296
|
+
*
|
|
297
|
+
* Operators have readable names for low-coders and short aliases for developers.
|
|
298
|
+
* Both forms work identically:
|
|
299
|
+
* - #greater_than(10) or #gt(10)
|
|
300
|
+
* - #one_of(a,b,c) or #in(a,b,c)
|
|
301
|
+
*/
|
|
302
|
+
export const builtinOperators = {
|
|
303
|
+
// Comparison operators (readable names)
|
|
304
|
+
equals: equalsOperator,
|
|
305
|
+
contains: containsOperator,
|
|
306
|
+
exists: existsOperator,
|
|
307
|
+
matches: matchesOperator,
|
|
308
|
+
greater_than: gtOperator,
|
|
309
|
+
greater_than_or_equal: gteOperator,
|
|
310
|
+
less_than: ltOperator,
|
|
311
|
+
less_than_or_equal: lteOperator,
|
|
312
|
+
one_of: inOperator,
|
|
313
|
+
ai_judge: aiJudgeOperator,
|
|
314
|
+
// Short aliases for developers
|
|
315
|
+
gt: gtOperator,
|
|
316
|
+
gte: gteOperator,
|
|
317
|
+
lt: ltOperator,
|
|
318
|
+
lte: lteOperator,
|
|
319
|
+
in: inOperator,
|
|
320
|
+
};
|
|
321
|
+
/**
|
|
322
|
+
* Get an operator by name.
|
|
323
|
+
*
|
|
324
|
+
* @param name - The operator name (without #)
|
|
325
|
+
* @returns The operator definition or undefined
|
|
326
|
+
*/
|
|
327
|
+
export function getOperator(name) {
|
|
328
|
+
return builtinOperators[name];
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* Check if an operator is async (AI-based).
|
|
332
|
+
*
|
|
333
|
+
* @param name - The operator name
|
|
334
|
+
* @returns true if the operator is async
|
|
335
|
+
*/
|
|
336
|
+
export function isAsyncOperator(name) {
|
|
337
|
+
const op = getOperator(name);
|
|
338
|
+
return op?.type === 'ai';
|
|
339
|
+
}
|
|
340
|
+
// =============================================================================
|
|
341
|
+
// IMPLEMENTATION NOTES
|
|
342
|
+
// =============================================================================
|
|
343
|
+
/*
|
|
344
|
+
NEXT STEPS TO IMPLEMENT:
|
|
345
|
+
|
|
346
|
+
1. AI JUDGE IMPLEMENTATION
|
|
347
|
+
- Create ai-judge/provider.ts for AI provider abstraction
|
|
348
|
+
- Implement OpenAI adapter
|
|
349
|
+
- Add caching layer
|
|
350
|
+
- Handle timeouts and errors gracefully
|
|
351
|
+
|
|
352
|
+
2. OPERATOR CONTEXT
|
|
353
|
+
The ai_judge operator needs access to the AI provider.
|
|
354
|
+
Options:
|
|
355
|
+
- Pass context as third argument to handler
|
|
356
|
+
- Use closure to capture config
|
|
357
|
+
- Create factory function that returns configured handler
|
|
358
|
+
|
|
359
|
+
3. ERROR HANDLING
|
|
360
|
+
- Invalid regex in #matches should not crash
|
|
361
|
+
- Type mismatches should return false (not throw)
|
|
362
|
+
- AI errors should be recoverable
|
|
363
|
+
|
|
364
|
+
4. TESTS
|
|
365
|
+
Create operators.test.ts with tests for:
|
|
366
|
+
- Each operator with various inputs
|
|
367
|
+
- Edge cases (null, undefined, empty)
|
|
368
|
+
- Type coercion behavior
|
|
369
|
+
- Async operator mocking
|
|
370
|
+
*/
|
|
371
|
+
//# sourceMappingURL=operators.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"operators.js","sourceRoot":"","sources":["../../src/evaluator/operators.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAIH,gFAAgF;AAChF,uBAAuB;AACvB,gFAAgF;AAEhF;;;;GAIG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O,EAAE,eAAe;IACxB,YAAY,EAAE,UAAU;IACxB,qBAAqB,EAAE,WAAW;IAClC,SAAS,EAAE,UAAU;IACrB,kBAAkB,EAAE,WAAW;IAC/B,MAAM,EAAE,UAAU;IAClB,QAAQ,EAAE,eAAe;IAEzB,+BAA+B;IAC/B,EAAE,EAAE,UAAU;IACd,GAAG,EAAE,WAAW;IAChB,EAAE,EAAE,UAAU;IACd,GAAG,EAAE,WAAW;IAChB,EAAE,EAAE,UAAU;CACf,CAAC;AAEF;;;;;GAKG;AACH,MAAM,UAAU,WAAW,CAAC,IAAY;IACtC,OAAO,gBAAgB,CAAC,IAAI,CAAC,CAAC;AAChC,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,eAAe,CAAC,IAAY;IAC1C,MAAM,EAAE,GAAG,WAAW,CAAC,IAAI,CAAC,CAAC;IAC7B,OAAO,EAAE,EAAE,IAAI,KAAK,IAAI,CAAC;AAC3B,CAAC;AAED,gFAAgF;AAChF,uBAAuB;AACvB,gFAAgF;AAEhF;;;;;;;;;;;;;;;;;;;;;;;;;;;EA2BE"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Echo PDK Core - Main entry point
|
|
3
|
+
*
|
|
4
|
+
* This is the main entry point for @goreal-ai/echo-pdk.
|
|
5
|
+
* It exports the createEcho factory function and all public types.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import { createEcho } from '@goreal-ai/echo-pdk';
|
|
10
|
+
*
|
|
11
|
+
* const echo = createEcho({
|
|
12
|
+
* strict: false,
|
|
13
|
+
* aiProvider: {
|
|
14
|
+
* type: 'openai',
|
|
15
|
+
* apiKey: process.env.OPENAI_API_KEY,
|
|
16
|
+
* }
|
|
17
|
+
* });
|
|
18
|
+
*
|
|
19
|
+
* const result = await echo.render(template, { name: 'Alice' });
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
export type { ASTNode, TextNode, VariableNode, ConditionalNode, SectionNode, ImportNode, IncludeNode, ConditionExpr, SourceLocation, EchoConfig, AIProviderConfig, ParseResult, ValidationResult, EchoError, EchoWarning, OperatorDefinition, OperatorHandler, EchoPlugin, Echo, } from './types.js';
|
|
23
|
+
import type { Echo, EchoConfig, EchoPlugin } from './types.js';
|
|
24
|
+
export { parse } from './parser/parser.js';
|
|
25
|
+
export { evaluate, resolveVariable, type ResolveVariableOptions, } from './evaluator/evaluator.js';
|
|
26
|
+
export { render, renderTemplate, formatErrors } from './renderer/renderer.js';
|
|
27
|
+
export { builtinOperators, getOperator } from './evaluator/operators.js';
|
|
28
|
+
export { createTextNode, createVariableNode, createConditionalNode, createConditionExpr, createSectionNode, createImportNode, createIncludeNode, collectAiJudgeConditions, visitNode, visitNodes, prettyPrint, } from './parser/ast.js';
|
|
29
|
+
/**
|
|
30
|
+
* Creates a new Echo instance with the given configuration.
|
|
31
|
+
*
|
|
32
|
+
* The Echo instance provides methods for parsing, validating, and rendering
|
|
33
|
+
* Echo templates with support for:
|
|
34
|
+
* - Variable interpolation: {{name}}, {{user.email}}
|
|
35
|
+
* - Conditionals: [#IF {{var}} #operator(arg)]...[END IF]
|
|
36
|
+
* - Sections: [#SECTION name="x"]...[END SECTION]
|
|
37
|
+
* - Includes: [#INCLUDE section_name]
|
|
38
|
+
* - AI-powered conditions: #ai_judge(question)
|
|
39
|
+
*
|
|
40
|
+
* @param config - Configuration options for the Echo instance
|
|
41
|
+
* @returns A configured Echo instance
|
|
42
|
+
*
|
|
43
|
+
* @example Basic usage
|
|
44
|
+
* ```typescript
|
|
45
|
+
* import { createEcho } from '@goreal-ai/echo-pdk';
|
|
46
|
+
*
|
|
47
|
+
* const echo = createEcho();
|
|
48
|
+
* const output = await echo.render('Hello {{name}}!', { name: 'World' });
|
|
49
|
+
* // Output: "Hello World!"
|
|
50
|
+
* ```
|
|
51
|
+
*
|
|
52
|
+
* @example With AI provider
|
|
53
|
+
* ```typescript
|
|
54
|
+
* const echo = createEcho({
|
|
55
|
+
* aiProvider: {
|
|
56
|
+
* type: 'openai',
|
|
57
|
+
* apiKey: process.env.OPENAI_API_KEY,
|
|
58
|
+
* model: 'gpt-4o-mini',
|
|
59
|
+
* }
|
|
60
|
+
* });
|
|
61
|
+
*
|
|
62
|
+
* const template = `
|
|
63
|
+
* [#IF {{content}} #ai_judge(Is this appropriate for children?)]
|
|
64
|
+
* Safe content: {{content}}
|
|
65
|
+
* [ELSE]
|
|
66
|
+
* Content flagged for review.
|
|
67
|
+
* [END IF]
|
|
68
|
+
* `;
|
|
69
|
+
*
|
|
70
|
+
* const output = await echo.render(template, { content: userContent });
|
|
71
|
+
* ```
|
|
72
|
+
*
|
|
73
|
+
* @example With plugins
|
|
74
|
+
* ```typescript
|
|
75
|
+
* const echo = createEcho();
|
|
76
|
+
*
|
|
77
|
+
* echo.loadPlugin({
|
|
78
|
+
* name: 'custom-operators',
|
|
79
|
+
* version: '1.0.0',
|
|
80
|
+
* operators: {
|
|
81
|
+
* isEmpty: {
|
|
82
|
+
* type: 'unary',
|
|
83
|
+
* handler: (value) => !value || value === '',
|
|
84
|
+
* description: 'Check if value is empty',
|
|
85
|
+
* }
|
|
86
|
+
* }
|
|
87
|
+
* });
|
|
88
|
+
* ```
|
|
89
|
+
*/
|
|
90
|
+
export declare function createEcho(config?: EchoConfig): Echo;
|
|
91
|
+
/**
|
|
92
|
+
* Helper function for defining plugins with type safety.
|
|
93
|
+
*
|
|
94
|
+
* @param plugin - The plugin definition
|
|
95
|
+
* @returns The same plugin (for type inference)
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* ```typescript
|
|
99
|
+
* import { definePlugin } from '@goreal-ai/echo-pdk';
|
|
100
|
+
*
|
|
101
|
+
* export default definePlugin({
|
|
102
|
+
* name: 'my-operators',
|
|
103
|
+
* version: '1.0.0',
|
|
104
|
+
* operators: {
|
|
105
|
+
* isEmpty: {
|
|
106
|
+
* type: 'unary',
|
|
107
|
+
* handler: (value) => !value,
|
|
108
|
+
* description: 'Check if value is empty'
|
|
109
|
+
* }
|
|
110
|
+
* }
|
|
111
|
+
* });
|
|
112
|
+
* ```
|
|
113
|
+
*/
|
|
114
|
+
export declare function definePlugin(plugin: EchoPlugin): EchoPlugin;
|
|
115
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAGH,YAAY,EAEV,OAAO,EACP,QAAQ,EACR,YAAY,EACZ,eAAe,EACf,WAAW,EACX,UAAU,EACV,WAAW,EACX,aAAa,EACb,cAAc,EAEd,UAAU,EACV,gBAAgB,EAEhB,WAAW,EACX,gBAAgB,EAChB,SAAS,EACT,WAAW,EAEX,kBAAkB,EAClB,eAAe,EACf,UAAU,EAEV,IAAI,GACL,MAAM,YAAY,CAAC;AAEpB,OAAO,KAAK,EACV,IAAI,EACJ,UAAU,EAIV,UAAU,EAGX,MAAM,YAAY,CAAC;AAUpB,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EACL,QAAQ,EACR,eAAe,EACf,KAAK,sBAAsB,GAC5B,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAC9E,OAAO,EAAE,gBAAgB,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACzE,OAAO,EACL,cAAc,EACd,kBAAkB,EAClB,qBAAqB,EACrB,mBAAmB,EACnB,iBAAiB,EACjB,gBAAgB,EAChB,iBAAiB,EACjB,wBAAwB,EACxB,SAAS,EACT,UAAU,EACV,WAAW,GACZ,MAAM,iBAAiB,CAAC;AAQzB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4DG;AACH,wBAAgB,UAAU,CAAC,MAAM,GAAE,UAAe,GAAG,IAAI,CA+IxD;AAuLD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,UAAU,GAAG,UAAU,CAE3D"}
|