@itz4blitz/agentful 0.2.0 → 0.3.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.
@@ -1,153 +0,0 @@
1
- /**
2
- * Template Engine
3
- *
4
- * Simple template engine for variable interpolation in agent templates.
5
- * Supports nested objects, arrays, and conditional rendering.
6
- */
7
-
8
- class TemplateEngine {
9
- /**
10
- * Render template with data
11
- */
12
- static render(template, data) {
13
- let content = template;
14
-
15
- // Handle arrays and objects with special formatting FIRST
16
- content = this.formatComplexTypes(content, data);
17
-
18
- // Replace simple variables: {{variable}}
19
- content = this.replaceVariables(content, data);
20
-
21
- // Add timestamp if needed
22
- if (content.includes('{{generated_at}}')) {
23
- content = content.replace(/\{\{generated_at\}\}/g, new Date().toISOString());
24
- }
25
-
26
- return content;
27
- }
28
-
29
- /**
30
- * Replace simple variables
31
- */
32
- static replaceVariables(content, data) {
33
- for (const [key, value] of Object.entries(data)) {
34
- const placeholder = new RegExp(`\\{\\{${key}\\}\\}`, 'g');
35
- content = content.replace(placeholder, this.formatValue(value));
36
- }
37
- return content;
38
- }
39
-
40
- /**
41
- * Format complex types (arrays, objects)
42
- */
43
- static formatComplexTypes(content, data) {
44
- // Handle code_samples first (before generic samples check)
45
- if (data.codeSamples && Array.isArray(data.codeSamples)) {
46
- const placeholder = new RegExp('\\{\\{code_samples\\}\\}', 'g');
47
- const formatted = this.formatSamples(data.codeSamples);
48
- content = content.replace(placeholder, formatted);
49
- }
50
-
51
- // Handle samples array
52
- if (data.samples && Array.isArray(data.samples)) {
53
- const placeholder = new RegExp('\\{\\{samples\\}\\}', 'g');
54
- const formatted = this.formatSamples(data.samples);
55
- content = content.replace(placeholder, formatted);
56
- }
57
- // Handle patterns array - format as bullet points
58
- if (data.patterns && Array.isArray(data.patterns)) {
59
- const placeholder = new RegExp('\\{\\{patterns\\}\\}', 'g');
60
- const formatted = data.patterns
61
- .map(p => {
62
- if (typeof p === 'string') return `- ${p}`;
63
- if (p.keyword && p.context) {
64
- return `- **${p.keyword}**: Found in codebase`;
65
- }
66
- return JSON.stringify(p);
67
- })
68
- .join('\n');
69
- content = content.replace(placeholder, formatted);
70
- }
71
-
72
- // Handle conventions array
73
- if (data.conventions && Array.isArray(data.conventions)) {
74
- const placeholder = new RegExp('\\{\\{conventions\\}\\}', 'g');
75
- const formatted = data.conventions
76
- .filter(c => c && c.trim())
77
- .map(c => `- ${c}`)
78
- .join('\n');
79
- content = content.replace(placeholder, formatted || 'No specific conventions detected');
80
- }
81
-
82
- // Handle features array
83
- if (data.features && Array.isArray(data.features)) {
84
- const placeholder = new RegExp('\\{\\{features\\}\\}', 'g');
85
- const formatted = data.features
86
- .map(f => `- **${f.name}**: ${f.description || 'No description'}`)
87
- .join('\n');
88
- content = content.replace(placeholder, formatted || 'No features detected');
89
- }
90
-
91
- // Handle endpoints array
92
- if (data.endpoints && Array.isArray(data.endpoints)) {
93
- const placeholder = new RegExp('\\{\\{endpoints\\}\\}', 'g');
94
- const formatted = data.endpoints
95
- .map(e => `- \`${e.code || e}\``)
96
- .join('\n');
97
- content = content.replace(placeholder, formatted || 'No endpoints detected');
98
- }
99
-
100
- // Handle models array
101
- if (data.models && Array.isArray(data.models)) {
102
- const placeholder = new RegExp('\\{\\{models\\}\\}', 'g');
103
- const formatted = data.models
104
- .map(m => `- \`${m.code || m}\``)
105
- .join('\n');
106
- content = content.replace(placeholder, formatted || 'No models detected');
107
- }
108
-
109
- return content;
110
- }
111
-
112
- /**
113
- * Format code samples for display
114
- */
115
- static formatSamples(samples) {
116
- if (!samples || samples.length === 0) {
117
- return 'No code samples available yet.';
118
- }
119
-
120
- return samples
121
- .slice(0, 5) // Limit to 5 samples
122
- .map(sample => {
123
- if (typeof sample === 'string') return sample;
124
-
125
- const path = sample.path || 'unknown';
126
- const content = sample.content || '';
127
-
128
- return `#### ${path}\n\`\`\`\n${content.substring(0, 800)}${content.length > 800 ? '\n...' : ''}\n\`\`\``;
129
- })
130
- .join('\n\n');
131
- }
132
-
133
- /**
134
- * Format value for template
135
- */
136
- static formatValue(value) {
137
- if (value === null || value === undefined) {
138
- return '';
139
- }
140
-
141
- if (Array.isArray(value)) {
142
- return value.join(', ');
143
- }
144
-
145
- if (typeof value === 'object') {
146
- return JSON.stringify(value, null, 2);
147
- }
148
-
149
- return String(value);
150
- }
151
- }
152
-
153
- export default TemplateEngine;