@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.
Files changed (53) hide show
  1. package/dist/ai-judge/index.d.ts +177 -0
  2. package/dist/ai-judge/index.d.ts.map +1 -0
  3. package/dist/ai-judge/index.js +299 -0
  4. package/dist/ai-judge/index.js.map +1 -0
  5. package/dist/evaluator/evaluator.d.ts +136 -0
  6. package/dist/evaluator/evaluator.d.ts.map +1 -0
  7. package/dist/evaluator/evaluator.js +407 -0
  8. package/dist/evaluator/evaluator.js.map +1 -0
  9. package/dist/evaluator/index.d.ts +7 -0
  10. package/dist/evaluator/index.d.ts.map +1 -0
  11. package/dist/evaluator/index.js +8 -0
  12. package/dist/evaluator/index.js.map +1 -0
  13. package/dist/evaluator/operators.d.ts +105 -0
  14. package/dist/evaluator/operators.d.ts.map +1 -0
  15. package/dist/evaluator/operators.js +371 -0
  16. package/dist/evaluator/operators.js.map +1 -0
  17. package/dist/index.d.ts +115 -0
  18. package/dist/index.d.ts.map +1 -0
  19. package/dist/index.js +388 -0
  20. package/dist/index.js.map +1 -0
  21. package/dist/parser/ast.d.ts +106 -0
  22. package/dist/parser/ast.d.ts.map +1 -0
  23. package/dist/parser/ast.js +260 -0
  24. package/dist/parser/ast.js.map +1 -0
  25. package/dist/parser/index.d.ts +8 -0
  26. package/dist/parser/index.d.ts.map +1 -0
  27. package/dist/parser/index.js +13 -0
  28. package/dist/parser/index.js.map +1 -0
  29. package/dist/parser/lexer.d.ts +199 -0
  30. package/dist/parser/lexer.d.ts.map +1 -0
  31. package/dist/parser/lexer.js +491 -0
  32. package/dist/parser/lexer.js.map +1 -0
  33. package/dist/parser/parser.d.ts +49 -0
  34. package/dist/parser/parser.d.ts.map +1 -0
  35. package/dist/parser/parser.js +615 -0
  36. package/dist/parser/parser.js.map +1 -0
  37. package/dist/plugins/index.d.ts +62 -0
  38. package/dist/plugins/index.d.ts.map +1 -0
  39. package/dist/plugins/index.js +170 -0
  40. package/dist/plugins/index.js.map +1 -0
  41. package/dist/renderer/index.d.ts +6 -0
  42. package/dist/renderer/index.d.ts.map +1 -0
  43. package/dist/renderer/index.js +5 -0
  44. package/dist/renderer/index.js.map +1 -0
  45. package/dist/renderer/renderer.d.ts +97 -0
  46. package/dist/renderer/renderer.d.ts.map +1 -0
  47. package/dist/renderer/renderer.js +243 -0
  48. package/dist/renderer/renderer.js.map +1 -0
  49. package/dist/types.d.ts +255 -0
  50. package/dist/types.d.ts.map +1 -0
  51. package/dist/types.js +9 -0
  52. package/dist/types.js.map +1 -0
  53. package/package.json +54 -0
@@ -0,0 +1,255 @@
1
+ /**
2
+ * @fileoverview Core type definitions for Echo PDK
3
+ *
4
+ * IMPLEMENTATION NOTES:
5
+ * This file defines all the core types used throughout the Echo engine.
6
+ * Keep types here to maintain a single source of truth and enable easy imports.
7
+ */
8
+ /**
9
+ * Represents a position in the source template for error reporting.
10
+ */
11
+ export interface SourceLocation {
12
+ /** Starting line number (1-indexed) */
13
+ startLine: number;
14
+ /** Starting column number (1-indexed) */
15
+ startColumn: number;
16
+ /** Ending line number (1-indexed) */
17
+ endLine: number;
18
+ /** Ending column number (1-indexed) */
19
+ endColumn: number;
20
+ /** Optional: the source text at this location */
21
+ source?: string;
22
+ }
23
+ /**
24
+ * Base interface for all AST nodes.
25
+ * Every node must have a type and location for error reporting.
26
+ */
27
+ export interface BaseNode {
28
+ type: string;
29
+ location: SourceLocation;
30
+ }
31
+ /**
32
+ * Plain text content in the template.
33
+ * Example: "Hello world" in "Hello world {{name}}"
34
+ */
35
+ export interface TextNode extends BaseNode {
36
+ type: 'text';
37
+ value: string;
38
+ }
39
+ /**
40
+ * Variable reference in the template.
41
+ * Example: {{user.name}} or {{value ?? "default"}}
42
+ */
43
+ export interface VariableNode extends BaseNode {
44
+ type: 'variable';
45
+ /** The variable path, e.g., "user.name" or "items[0]" */
46
+ path: string;
47
+ /** Optional default value if variable is undefined */
48
+ defaultValue?: string;
49
+ }
50
+ /**
51
+ * A condition expression used in [#IF] blocks.
52
+ */
53
+ export interface ConditionExpr {
54
+ /** The variable being tested */
55
+ variable: string;
56
+ /** The operator name, e.g., 'equals', 'contains', 'ai_judge' */
57
+ operator: string;
58
+ /** The argument to the operator (if any) */
59
+ argument?: string | number | string[];
60
+ /** Flag for optimization: true if this is an AI judge condition */
61
+ isAiJudge: boolean;
62
+ }
63
+ /**
64
+ * Conditional block: [#IF]...[ELSE IF]...[ELSE]...[END IF]
65
+ */
66
+ export interface ConditionalNode extends BaseNode {
67
+ type: 'conditional';
68
+ /** The condition to evaluate */
69
+ condition: ConditionExpr;
70
+ /** Nodes to render if condition is true */
71
+ consequent: ASTNode[];
72
+ /** Optional: ELSE IF or ELSE branch */
73
+ alternate?: ConditionalNode | ASTNode[];
74
+ }
75
+ /**
76
+ * Section definition: [#SECTION name="..."]...[END SECTION]
77
+ */
78
+ export interface SectionNode extends BaseNode {
79
+ type: 'section';
80
+ /** The section name for later reference */
81
+ name: string;
82
+ /** The content of the section */
83
+ body: ASTNode[];
84
+ }
85
+ /**
86
+ * Import directive: [#IMPORT ./path/to/file.echo]
87
+ */
88
+ export interface ImportNode extends BaseNode {
89
+ type: 'import';
90
+ /** The path to import (relative or absolute) */
91
+ path: string;
92
+ }
93
+ /**
94
+ * Include directive: [#INCLUDE section_name]
95
+ */
96
+ export interface IncludeNode extends BaseNode {
97
+ type: 'include';
98
+ /** The name of the section to include */
99
+ name: string;
100
+ }
101
+ /**
102
+ * Union type of all possible AST nodes.
103
+ */
104
+ export type ASTNode = TextNode | VariableNode | ConditionalNode | SectionNode | ImportNode | IncludeNode;
105
+ /**
106
+ * Handler function for a comparison operator.
107
+ * Called with the variable value and the operator argument.
108
+ */
109
+ export type OperatorHandler = (value: unknown, argument?: unknown) => boolean | Promise<boolean>;
110
+ /**
111
+ * Definition of an operator for the plugin system.
112
+ */
113
+ export interface OperatorDefinition {
114
+ /** Type of operator: comparison (takes arg), unary (no arg), or ai (async) */
115
+ type: 'comparison' | 'unary' | 'ai';
116
+ /** The handler function */
117
+ handler: OperatorHandler;
118
+ /** Human-readable description */
119
+ description: string;
120
+ /** Example usage */
121
+ example?: string;
122
+ /** Autocomplete configuration for IDEs */
123
+ autocomplete?: {
124
+ trigger: string;
125
+ snippet: string;
126
+ };
127
+ }
128
+ /**
129
+ * AI provider configuration for #ai_judge operator.
130
+ */
131
+ export interface AIProviderConfig {
132
+ /** The provider type */
133
+ type: 'openai' | 'anthropic';
134
+ /** API key (can also be set via ECHO_AI_API_KEY env var) */
135
+ apiKey: string;
136
+ /** Model to use (defaults to provider's default) */
137
+ model?: string;
138
+ /** Timeout in milliseconds */
139
+ timeout?: number;
140
+ }
141
+ /**
142
+ * Main Echo configuration object.
143
+ */
144
+ export interface EchoConfig {
145
+ /** Strict mode: fail on errors vs warn and continue */
146
+ strict?: boolean;
147
+ /** AI provider configuration for #ai_judge */
148
+ aiProvider?: AIProviderConfig;
149
+ /** Plugin paths to load */
150
+ plugins?: string[];
151
+ /** Language definition file path */
152
+ languagePath?: string;
153
+ }
154
+ /**
155
+ * Result of parsing a template.
156
+ */
157
+ export interface ParseResult {
158
+ /** Whether parsing succeeded */
159
+ success: boolean;
160
+ /** The AST if successful */
161
+ ast?: ASTNode[];
162
+ /** Errors encountered during parsing */
163
+ errors: EchoError[];
164
+ }
165
+ /**
166
+ * Result of validating a template.
167
+ */
168
+ export interface ValidationResult {
169
+ /** Whether validation passed */
170
+ valid: boolean;
171
+ /** Errors found */
172
+ errors: EchoError[];
173
+ /** Warnings (non-fatal issues) */
174
+ warnings: EchoWarning[];
175
+ }
176
+ /**
177
+ * An error in the Echo template.
178
+ */
179
+ export interface EchoError {
180
+ /** Error code for programmatic handling */
181
+ code: string;
182
+ /** Human-readable error message */
183
+ message: string;
184
+ /** Location in source */
185
+ location?: SourceLocation;
186
+ }
187
+ /**
188
+ * A warning (non-fatal issue) in the Echo template.
189
+ */
190
+ export interface EchoWarning {
191
+ /** Warning code */
192
+ code: string;
193
+ /** Human-readable warning message */
194
+ message: string;
195
+ /** Location in source */
196
+ location?: SourceLocation;
197
+ }
198
+ /**
199
+ * Plugin definition for extending Echo.
200
+ */
201
+ export interface EchoPlugin {
202
+ /** Plugin name (unique identifier) */
203
+ name: string;
204
+ /** Plugin version */
205
+ version: string;
206
+ /** Custom operators provided by this plugin */
207
+ operators?: Record<string, OperatorDefinition>;
208
+ /** Hook called when plugin is loaded */
209
+ onLoad?: () => void | Promise<void>;
210
+ }
211
+ /**
212
+ * Helper function type for defining plugins.
213
+ */
214
+ export type DefinePlugin = (plugin: EchoPlugin) => EchoPlugin;
215
+ /**
216
+ * The main Echo interface for parsing and rendering templates.
217
+ */
218
+ export interface Echo {
219
+ /**
220
+ * Parse a template string into an AST.
221
+ * @param template - The Echo template string
222
+ * @returns ParseResult with AST or errors
223
+ */
224
+ parse(template: string): ParseResult;
225
+ /**
226
+ * Render a template with the given context.
227
+ * @param template - The Echo template string
228
+ * @param context - Variables to substitute
229
+ * @returns The rendered string
230
+ */
231
+ render(template: string, context: Record<string, unknown>): Promise<string>;
232
+ /**
233
+ * Validate a template for syntax and semantic errors.
234
+ * @param template - The Echo template string
235
+ * @returns ValidationResult with errors and warnings
236
+ */
237
+ validate(template: string): ValidationResult;
238
+ /**
239
+ * Load a language definition from a YAML file.
240
+ * @param yamlPath - Path to the echo.lang.yaml file
241
+ */
242
+ loadLanguage(yamlPath: string): void;
243
+ /**
244
+ * Register a custom operator.
245
+ * @param name - The operator name (without #)
246
+ * @param definition - The operator definition
247
+ */
248
+ registerOperator(name: string, definition: OperatorDefinition): void;
249
+ /**
250
+ * Load a plugin.
251
+ * @param plugin - The plugin to load
252
+ */
253
+ loadPlugin(plugin: EchoPlugin): void;
254
+ }
255
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAMH;;GAEG;AACH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C;IAC/C,wCAAwC;IACxC,MAAM,CAAC,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACrC;AAED;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG,CAAC,MAAM,EAAE,UAAU,KAAK,UAAU,CAAC;AAM9D;;GAEG;AACH,MAAM,WAAW,IAAI;IACnB;;;;OAIG;IACH,KAAK,CAAC,QAAQ,EAAE,MAAM,GAAG,WAAW,CAAC;IAErC;;;;;OAKG;IACH,MAAM,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAE5E;;;;OAIG;IACH,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,gBAAgB,CAAC;IAE7C;;;OAGG;IACH,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IAErC;;;;OAIG;IACH,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,EAAE,kBAAkB,GAAG,IAAI,CAAC;IAErE;;;OAGG;IACH,UAAU,CAAC,MAAM,EAAE,UAAU,GAAG,IAAI,CAAC;CACtC"}
package/dist/types.js ADDED
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @fileoverview Core type definitions for Echo PDK
3
+ *
4
+ * IMPLEMENTATION NOTES:
5
+ * This file defines all the core types used throughout the Echo engine.
6
+ * Keep types here to maintain a single source of truth and enable easy imports.
7
+ */
8
+ export {};
9
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG"}
package/package.json ADDED
@@ -0,0 +1,54 @@
1
+ {
2
+ "name": "@goreal-ai/echo-pdk",
3
+ "version": "0.1.0",
4
+ "description": "Echo PDK core rendering engine - parser, evaluator, and renderer",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js"
12
+ }
13
+ },
14
+ "files": [
15
+ "dist"
16
+ ],
17
+ "scripts": {
18
+ "build": "tsc",
19
+ "dev": "tsc --watch",
20
+ "test": "vitest run",
21
+ "test:watch": "vitest",
22
+ "lint": "eslint src --ext .ts",
23
+ "lint:fix": "eslint src --ext .ts --fix",
24
+ "typecheck": "tsc --noEmit",
25
+ "clean": "rm -rf dist"
26
+ },
27
+ "dependencies": {
28
+ "chevrotain": "^11.0.0",
29
+ "yaml": "^2.3.0"
30
+ },
31
+ "peerDependencies": {
32
+ "openai": "^4.0.0"
33
+ },
34
+ "peerDependenciesMeta": {
35
+ "openai": {
36
+ "optional": true
37
+ }
38
+ },
39
+ "devDependencies": {
40
+ "@types/node": "^20.10.0",
41
+ "openai": "^4.0.0",
42
+ "typescript": "^5.3.0",
43
+ "vitest": "^2.0.0"
44
+ },
45
+ "keywords": [
46
+ "echo",
47
+ "pdk",
48
+ "prompt",
49
+ "dsl",
50
+ "parser",
51
+ "templating"
52
+ ],
53
+ "license": "MIT"
54
+ }