genai-lite 0.4.0 → 0.4.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.
Files changed (59) hide show
  1. package/README.md +47 -37
  2. package/dist/llm/LLMService.d.ts +29 -2
  3. package/dist/llm/LLMService.js +67 -36
  4. package/dist/llm/config.js +4 -4
  5. package/dist/llm/services/SettingsManager.js +17 -11
  6. package/dist/llm/types.d.ts +81 -22
  7. package/dist/prompting/parser.d.ts +2 -2
  8. package/dist/prompting/parser.js +2 -2
  9. package/package.json +1 -1
  10. package/dist/llm/LLMService.createMessages.test.d.ts +0 -4
  11. package/dist/llm/LLMService.createMessages.test.js +0 -364
  12. package/dist/llm/LLMService.original.d.ts +0 -147
  13. package/dist/llm/LLMService.original.js +0 -656
  14. package/dist/llm/LLMService.prepareMessage.test.d.ts +0 -1
  15. package/dist/llm/LLMService.prepareMessage.test.js +0 -303
  16. package/dist/llm/LLMService.presets.test.d.ts +0 -1
  17. package/dist/llm/LLMService.presets.test.js +0 -210
  18. package/dist/llm/LLMService.sendMessage.preset.test.d.ts +0 -1
  19. package/dist/llm/LLMService.sendMessage.preset.test.js +0 -153
  20. package/dist/llm/LLMService.test.d.ts +0 -1
  21. package/dist/llm/LLMService.test.js +0 -639
  22. package/dist/llm/clients/AnthropicClientAdapter.test.d.ts +0 -1
  23. package/dist/llm/clients/AnthropicClientAdapter.test.js +0 -273
  24. package/dist/llm/clients/GeminiClientAdapter.test.d.ts +0 -1
  25. package/dist/llm/clients/GeminiClientAdapter.test.js +0 -405
  26. package/dist/llm/clients/LlamaCppClientAdapter.test.d.ts +0 -1
  27. package/dist/llm/clients/LlamaCppClientAdapter.test.js +0 -447
  28. package/dist/llm/clients/LlamaCppServerClient.test.d.ts +0 -1
  29. package/dist/llm/clients/LlamaCppServerClient.test.js +0 -294
  30. package/dist/llm/clients/MockClientAdapter.test.d.ts +0 -1
  31. package/dist/llm/clients/MockClientAdapter.test.js +0 -250
  32. package/dist/llm/clients/OpenAIClientAdapter.test.d.ts +0 -1
  33. package/dist/llm/clients/OpenAIClientAdapter.test.js +0 -258
  34. package/dist/llm/clients/adapterErrorUtils.test.d.ts +0 -1
  35. package/dist/llm/clients/adapterErrorUtils.test.js +0 -123
  36. package/dist/llm/config.test.d.ts +0 -1
  37. package/dist/llm/config.test.js +0 -176
  38. package/dist/llm/services/AdapterRegistry.test.d.ts +0 -1
  39. package/dist/llm/services/AdapterRegistry.test.js +0 -239
  40. package/dist/llm/services/ModelResolver.test.d.ts +0 -1
  41. package/dist/llm/services/ModelResolver.test.js +0 -179
  42. package/dist/llm/services/PresetManager.test.d.ts +0 -1
  43. package/dist/llm/services/PresetManager.test.js +0 -210
  44. package/dist/llm/services/RequestValidator.test.d.ts +0 -1
  45. package/dist/llm/services/RequestValidator.test.js +0 -159
  46. package/dist/llm/services/SettingsManager.test.d.ts +0 -1
  47. package/dist/llm/services/SettingsManager.test.js +0 -266
  48. package/dist/prompting/builder.d.ts +0 -38
  49. package/dist/prompting/builder.js +0 -63
  50. package/dist/prompting/builder.test.d.ts +0 -4
  51. package/dist/prompting/builder.test.js +0 -109
  52. package/dist/prompting/content.test.d.ts +0 -4
  53. package/dist/prompting/content.test.js +0 -212
  54. package/dist/prompting/parser.test.d.ts +0 -4
  55. package/dist/prompting/parser.test.js +0 -464
  56. package/dist/prompting/template.test.d.ts +0 -1
  57. package/dist/prompting/template.test.js +0 -250
  58. package/dist/providers/fromEnvironment.test.d.ts +0 -1
  59. package/dist/providers/fromEnvironment.test.js +0 -59
@@ -1,250 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const template_1 = require("./template");
4
- describe('renderTemplate', () => {
5
- it('should handle simple variable substitution', () => {
6
- const template = 'Hello, {{ name }}!';
7
- const result = (0, template_1.renderTemplate)(template, { name: 'World' });
8
- expect(result).toBe('Hello, World!');
9
- });
10
- it('should handle intelligent newline trimming for empty results', () => {
11
- const template = 'Start\n{{ showDetails ? `Details here` : `` }}\nEnd';
12
- const result = (0, template_1.renderTemplate)(template, { showDetails: false });
13
- expect(result).toBe('Start\nEnd');
14
- });
15
- it('should preserve newlines for non-empty results', () => {
16
- const template = 'Start\n{{ showDetails ? `Details here` : `` }}\nEnd';
17
- const result = (0, template_1.renderTemplate)(template, { showDetails: true });
18
- expect(result).toBe('Start\nDetails here\nEnd');
19
- });
20
- it('should correctly parse ternary logic with backtick-delimited strings', () => {
21
- const template = '{{ condition ? `A` : `B` }}';
22
- expect((0, template_1.renderTemplate)(template, { condition: true })).toBe('A');
23
- expect((0, template_1.renderTemplate)(template, { condition: false })).toBe('B');
24
- });
25
- it('should handle multi-line strings in backticks', () => {
26
- const template = '{{ condition ? `Line 1\nLine 2` : `Single Line` }}';
27
- const result = (0, template_1.renderTemplate)(template, { condition: true });
28
- expect(result).toBe('Line 1\nLine 2');
29
- });
30
- it('should handle ternary expressions with only a true part', () => {
31
- const template = 'Data: {{ data ? `{{data}}` : `` }}';
32
- expect((0, template_1.renderTemplate)(template, { data: 'Exists' })).toBe('Data: Exists');
33
- expect((0, template_1.renderTemplate)(template, { data: false })).toBe('Data: ');
34
- });
35
- it('should handle escaped backticks within the template strings', () => {
36
- const template = '{{ flag ? `This is a \\`backtick\\`` : `` }}';
37
- const result = (0, template_1.renderTemplate)(template, { flag: true });
38
- expect(result).toBe('This is a `backtick`');
39
- });
40
- it('should handle undefined variables', () => {
41
- const template = 'Value: {{ undefinedVar }}';
42
- const result = (0, template_1.renderTemplate)(template, {});
43
- expect(result).toBe('Value: ');
44
- });
45
- it('should handle boolean values', () => {
46
- const template = 'Boolean: {{ boolValue }}';
47
- expect((0, template_1.renderTemplate)(template, { boolValue: true })).toBe('Boolean: true');
48
- expect((0, template_1.renderTemplate)(template, { boolValue: false })).toBe('Boolean: false');
49
- });
50
- it('should handle numeric values', () => {
51
- const template = 'Number: {{ numValue }}';
52
- expect((0, template_1.renderTemplate)(template, { numValue: 42 })).toBe('Number: 42');
53
- expect((0, template_1.renderTemplate)(template, { numValue: 0 })).toBe('Number: 0');
54
- });
55
- it('should handle nested variable substitution in ternary true branch', () => {
56
- const template = '{{ showName ? `Hello, {{name}}!` : `Hello, stranger!` }}';
57
- const result = (0, template_1.renderTemplate)(template, { showName: true, name: 'Alice' });
58
- expect(result).toBe('Hello, Alice!');
59
- });
60
- it('should handle nested variable substitution in ternary false branch', () => {
61
- const template = '{{ showName ? `Hello, {{name}}!` : `Hello, {{fallback}}!` }}';
62
- const result = (0, template_1.renderTemplate)(template, { showName: false, fallback: 'Guest' });
63
- expect(result).toBe('Hello, Guest!');
64
- });
65
- it('should handle multiple variable substitutions', () => {
66
- const template = '{{ greeting }}, {{ name }}! {{ farewell }}';
67
- const result = (0, template_1.renderTemplate)(template, {
68
- greeting: 'Hello',
69
- name: 'World',
70
- farewell: 'Goodbye'
71
- });
72
- expect(result).toBe('Hello, World! Goodbye');
73
- });
74
- it('should handle special task_context variable with empty string', () => {
75
- const template = 'Context: {{ task_context }}';
76
- expect((0, template_1.renderTemplate)(template, { task_context: '' })).toBe('Context: ');
77
- expect((0, template_1.renderTemplate)(template, { task_context: ' ' })).toBe('Context: ');
78
- expect((0, template_1.renderTemplate)(template, { task_context: 'Some context' })).toBe('Context: Some context');
79
- });
80
- it('should handle complex nested templates', () => {
81
- const template = `
82
- Project: {{ projectName }}
83
- {{ hasFiles ? \`## Files
84
- {{ fileList }}\` : \`No files selected\` }}
85
- {{ showSummary ? \`
86
- ## Summary
87
- {{ summary }}\` : \`\` }}
88
- End
89
- `;
90
- const result = (0, template_1.renderTemplate)(template, {
91
- projectName: 'MyProject',
92
- hasFiles: true,
93
- fileList: '- file1.js\n- file2.js',
94
- showSummary: false,
95
- summary: 'This is a summary'
96
- });
97
- expect(result).toBe(`
98
- Project: MyProject
99
- ## Files
100
- - file1.js
101
- - file2.js
102
- End
103
- `);
104
- });
105
- it('should handle backward compatible quote-based ternary syntax', () => {
106
- const template = '{{ condition ? "True value" : "False value" }}';
107
- expect((0, template_1.renderTemplate)(template, { condition: true })).toBe('True value');
108
- expect((0, template_1.renderTemplate)(template, { condition: false })).toBe('False value');
109
- });
110
- it('should handle single quotes in backward compatible syntax', () => {
111
- const template = "{{ condition ? 'True value' : 'False value' }}";
112
- expect((0, template_1.renderTemplate)(template, { condition: true })).toBe('True value');
113
- expect((0, template_1.renderTemplate)(template, { condition: false })).toBe('False value');
114
- });
115
- it('should handle whitespace around expressions', () => {
116
- const template = '{{ name }}';
117
- const result = (0, template_1.renderTemplate)(template, { name: 'Test' });
118
- expect(result).toBe('Test');
119
- });
120
- it('should handle whitespace in ternary expressions', () => {
121
- const template = '{{ condition ? `True` : `False` }}';
122
- expect((0, template_1.renderTemplate)(template, { condition: true })).toBe('True');
123
- });
124
- it('should handle empty template', () => {
125
- const template = '';
126
- const result = (0, template_1.renderTemplate)(template, { any: 'value' });
127
- expect(result).toBe('');
128
- });
129
- it('should handle template with no placeholders', () => {
130
- const template = 'Just plain text';
131
- const result = (0, template_1.renderTemplate)(template, { any: 'value' });
132
- expect(result).toBe('Just plain text');
133
- });
134
- describe('colon handling in quoted strings', () => {
135
- it('should handle colon in double-quoted true branch', () => {
136
- const template = '{{ isDraft ? "Note: This is a draft" : "Published" }}';
137
- expect((0, template_1.renderTemplate)(template, { isDraft: true })).toBe('Note: This is a draft');
138
- expect((0, template_1.renderTemplate)(template, { isDraft: false })).toBe('Published');
139
- });
140
- it('should handle colon in single-quoted true branch', () => {
141
- const template = "{{ isDraft ? 'Note: This is a draft' : 'Published' }}";
142
- expect((0, template_1.renderTemplate)(template, { isDraft: true })).toBe('Note: This is a draft');
143
- expect((0, template_1.renderTemplate)(template, { isDraft: false })).toBe('Published');
144
- });
145
- it('should handle colon in both branches', () => {
146
- const template = '{{ isDraft ? "Status: Draft" : "Status: Published" }}';
147
- expect((0, template_1.renderTemplate)(template, { isDraft: true })).toBe('Status: Draft');
148
- expect((0, template_1.renderTemplate)(template, { isDraft: false })).toBe('Status: Published');
149
- });
150
- it('should handle multiple colons in quoted strings', () => {
151
- const template = '{{ showTime ? "Time: 10:30:45" : "Time: Not available" }}';
152
- expect((0, template_1.renderTemplate)(template, { showTime: true })).toBe('Time: 10:30:45');
153
- expect((0, template_1.renderTemplate)(template, { showTime: false })).toBe('Time: Not available');
154
- });
155
- it('should handle escaped quotes with colons', () => {
156
- const template = '{{ useAdvanced ? "He said: \\"Hello\\"" : "Simple greeting" }}';
157
- expect((0, template_1.renderTemplate)(template, { useAdvanced: true })).toBe('He said: "Hello"');
158
- });
159
- it('should handle mixed quote types', () => {
160
- const template = `{{ showBoth ? "Bob's message: 'Hi there'" : 'Alice said: "Hello"' }}`;
161
- expect((0, template_1.renderTemplate)(template, { showBoth: true })).toBe("Bob's message: 'Hi there'");
162
- expect((0, template_1.renderTemplate)(template, { showBoth: false })).toBe('Alice said: "Hello"');
163
- });
164
- it('should handle URL-like strings with colons', () => {
165
- const template = '{{ useHttps ? "https://example.com" : "http://example.com" }}';
166
- expect((0, template_1.renderTemplate)(template, { useHttps: true })).toBe('https://example.com');
167
- expect((0, template_1.renderTemplate)(template, { useHttps: false })).toBe('http://example.com');
168
- });
169
- it('should work with backtick syntax (regression test)', () => {
170
- const template = '{{ isDraft ? `Note: This is a draft` : `Status: Published` }}';
171
- expect((0, template_1.renderTemplate)(template, { isDraft: true })).toBe('Note: This is a draft');
172
- expect((0, template_1.renderTemplate)(template, { isDraft: false })).toBe('Status: Published');
173
- });
174
- it('should handle no false branch with colon in true branch', () => {
175
- const template = '{{ showNote ? "Note: Important information" }}';
176
- expect((0, template_1.renderTemplate)(template, { showNote: true })).toBe('Note: Important information');
177
- expect((0, template_1.renderTemplate)(template, { showNote: false })).toBe('');
178
- });
179
- it('should handle colons with logical operators', () => {
180
- const template = '{{ isActive && hasAccess ? "Status: Active" : "Status: Inactive" }}';
181
- expect((0, template_1.renderTemplate)(template, { isActive: true, hasAccess: true })).toBe('Status: Active');
182
- expect((0, template_1.renderTemplate)(template, { isActive: false, hasAccess: true })).toBe('Status: Inactive');
183
- });
184
- });
185
- describe('logical operators in conditions', () => {
186
- it('should handle NOT operator (!)', () => {
187
- const template = '{{ !isDisabled ? `Enabled` : `Disabled` }}';
188
- expect((0, template_1.renderTemplate)(template, { isDisabled: false })).toBe('Enabled');
189
- expect((0, template_1.renderTemplate)(template, { isDisabled: true })).toBe('Disabled');
190
- });
191
- it('should handle AND operator (&&)', () => {
192
- const template = '{{ hasPermission && isActive ? `Show button` : `Hide button` }}';
193
- expect((0, template_1.renderTemplate)(template, { hasPermission: true, isActive: true })).toBe('Show button');
194
- expect((0, template_1.renderTemplate)(template, { hasPermission: true, isActive: false })).toBe('Hide button');
195
- expect((0, template_1.renderTemplate)(template, { hasPermission: false, isActive: true })).toBe('Hide button');
196
- expect((0, template_1.renderTemplate)(template, { hasPermission: false, isActive: false })).toBe('Hide button');
197
- });
198
- it('should handle OR operator (||)', () => {
199
- const template = '{{ isAdmin || isOwner ? `Has access` : `No access` }}';
200
- expect((0, template_1.renderTemplate)(template, { isAdmin: true, isOwner: false })).toBe('Has access');
201
- expect((0, template_1.renderTemplate)(template, { isAdmin: false, isOwner: true })).toBe('Has access');
202
- expect((0, template_1.renderTemplate)(template, { isAdmin: true, isOwner: true })).toBe('Has access');
203
- expect((0, template_1.renderTemplate)(template, { isAdmin: false, isOwner: false })).toBe('No access');
204
- });
205
- it('should handle NOT with AND', () => {
206
- const template = '{{ !isDraft && isPublished ? `Show public` : `Hide` }}';
207
- expect((0, template_1.renderTemplate)(template, { isDraft: false, isPublished: true })).toBe('Show public');
208
- expect((0, template_1.renderTemplate)(template, { isDraft: true, isPublished: true })).toBe('Hide');
209
- });
210
- it('should handle NOT with OR', () => {
211
- const template = '{{ !isBlocked || isAdmin ? `Allow` : `Deny` }}';
212
- expect((0, template_1.renderTemplate)(template, { isBlocked: false, isAdmin: false })).toBe('Allow');
213
- expect((0, template_1.renderTemplate)(template, { isBlocked: true, isAdmin: true })).toBe('Allow');
214
- expect((0, template_1.renderTemplate)(template, { isBlocked: true, isAdmin: false })).toBe('Deny');
215
- });
216
- it('should handle NOT on both sides of AND', () => {
217
- const template = '{{ !isLoading && !hasError ? `Ready` : `Not ready` }}';
218
- expect((0, template_1.renderTemplate)(template, { isLoading: false, hasError: false })).toBe('Ready');
219
- expect((0, template_1.renderTemplate)(template, { isLoading: true, hasError: false })).toBe('Not ready');
220
- expect((0, template_1.renderTemplate)(template, { isLoading: false, hasError: true })).toBe('Not ready');
221
- });
222
- it('should handle whitespace around operators', () => {
223
- const template = '{{ !isDisabled && isVisible ? `Show` : `Hide` }}';
224
- expect((0, template_1.renderTemplate)(template, { isDisabled: false, isVisible: true })).toBe('Show');
225
- });
226
- it('should handle undefined variables in logical expressions', () => {
227
- const template = '{{ undefinedVar && definedVar ? `Both true` : `At least one false` }}';
228
- expect((0, template_1.renderTemplate)(template, { definedVar: true })).toBe('At least one false');
229
- });
230
- it('should handle falsy values in logical expressions', () => {
231
- const template = '{{ nullVar || zero ? `Has truthy` : `All falsy` }}';
232
- expect((0, template_1.renderTemplate)(template, { nullVar: null, zero: 0 })).toBe('All falsy');
233
- const template2 = '{{ emptyString || text ? `Has truthy` : `All falsy` }}';
234
- expect((0, template_1.renderTemplate)(template2, { emptyString: '', text: 'hello' })).toBe('Has truthy');
235
- });
236
- it('should fallback to simple lookup for complex expressions', () => {
237
- // More than 2 operands should fallback
238
- const template = '{{ a && b && c ? `True` : `False` }}';
239
- const result = (0, template_1.renderTemplate)(template, { 'a && b && c': true });
240
- expect(result).toBe('True');
241
- });
242
- it('should handle nested templates with logical operators', () => {
243
- const template = '{{ showDetails && hasData ? `Details: {{data}}` : `No details` }}';
244
- expect((0, template_1.renderTemplate)(template, { showDetails: true, hasData: true, data: 'Important info' }))
245
- .toBe('Details: Important info');
246
- expect((0, template_1.renderTemplate)(template, { showDetails: false, hasData: true, data: 'Important info' }))
247
- .toBe('No details');
248
- });
249
- });
250
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,59 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const fromEnvironment_1 = require("./fromEnvironment");
4
- describe('fromEnvironment', () => {
5
- const OLD_ENV = process.env;
6
- beforeEach(() => {
7
- jest.resetModules(); // Clear cache
8
- process.env = { ...OLD_ENV }; // Make a copy
9
- });
10
- afterAll(() => {
11
- process.env = OLD_ENV; // Restore old environment
12
- });
13
- it('should retrieve an existing environment variable', async () => {
14
- process.env.OPENAI_API_KEY = 'test-openai-key';
15
- const key = await (0, fromEnvironment_1.fromEnvironment)('openai');
16
- expect(key).toBe('test-openai-key');
17
- });
18
- it('should convert provider ID to uppercase', async () => {
19
- process.env.ANTHROPIC_API_KEY = 'test-anthropic-key';
20
- const key = await (0, fromEnvironment_1.fromEnvironment)('anthropic');
21
- expect(key).toBe('test-anthropic-key');
22
- });
23
- it('should handle mixed case provider IDs', async () => {
24
- process.env.GEMINI_API_KEY = 'test-gemini-key';
25
- const key = await (0, fromEnvironment_1.fromEnvironment)('GeMiNi');
26
- expect(key).toBe('test-gemini-key');
27
- });
28
- it('should return null for a non-existent environment variable', async () => {
29
- const key = await (0, fromEnvironment_1.fromEnvironment)('nonexistent');
30
- expect(key).toBeNull();
31
- });
32
- it('should return null for empty provider ID', async () => {
33
- const key = await (0, fromEnvironment_1.fromEnvironment)('');
34
- expect(key).toBeNull();
35
- });
36
- it('should handle special characters in provider ID', async () => {
37
- process.env['PROVIDER-123_API_KEY'] = 'test-special-key';
38
- const key = await (0, fromEnvironment_1.fromEnvironment)('provider-123');
39
- expect(key).toBe('test-special-key');
40
- });
41
- it('should return null when environment variable exists but is empty', async () => {
42
- process.env.EMPTY_API_KEY = '';
43
- const key = await (0, fromEnvironment_1.fromEnvironment)('empty');
44
- expect(key).toBeNull(); // Empty string is falsy, so || null returns null
45
- });
46
- it('should return "not-needed" for llamacpp provider', async () => {
47
- const key = await (0, fromEnvironment_1.fromEnvironment)('llamacpp');
48
- expect(key).toBe('not-needed');
49
- });
50
- it('should return "not-needed" for mock provider', async () => {
51
- const key = await (0, fromEnvironment_1.fromEnvironment)('mock');
52
- expect(key).toBe('not-needed');
53
- });
54
- it('should return "not-needed" for llamacpp even if environment variable exists', async () => {
55
- process.env.LLAMACPP_API_KEY = 'should-not-be-used';
56
- const key = await (0, fromEnvironment_1.fromEnvironment)('llamacpp');
57
- expect(key).toBe('not-needed');
58
- });
59
- });