1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
|
- import type { ProviderOptions } from '../../src/types/providers';
- import { isApiProvider, isProviderOptions } from '../../src/types/providers';
- describe('isApiProvider', () => {
- it('should correctly identify valid ApiProvider objects', () => {
- const validProviders = [
- {
- id: () => 'test-provider',
- callApi: async () => ({ output: 'test' }),
- },
- {
- id: () => 'full-provider',
- callApi: async () => ({ output: 'test' }),
- callEmbeddingApi: async () => ({ embedding: [1, 2, 3] }),
- callClassificationApi: async () => ({ classification: { class1: 0.8 } }),
- config: { temperature: 0.7 },
- delay: 1000,
- getSessionId: () => 'session-123',
- label: 'Test Provider',
- transform: 'toLowerCase()',
- },
- {
- id: () => 'minimal-provider',
- callApi: jest.fn(),
- },
- ];
- validProviders.forEach((provider) => {
- expect(isApiProvider(provider)).toBe(true);
- });
- });
- it('should correctly identify invalid ApiProvider objects', () => {
- const invalidProviders = [
- null,
- undefined,
- {},
- { id: 'string-id' }, // id should be a function
- { id: null },
- { id: undefined },
- { id: 42 },
- 'string-provider',
- 42,
- true,
- [],
- new Date(),
- ];
- invalidProviders.forEach((provider) => {
- expect(isApiProvider(provider)).toBe(false);
- });
- });
- it('should return false for non-object values', () => {
- expect(isApiProvider('string')).toBe(false);
- expect(isApiProvider(123)).toBe(false);
- expect(isApiProvider(true)).toBe(false);
- expect(isApiProvider(undefined)).toBe(false);
- expect(isApiProvider(null)).toBe(false);
- });
- it('should return false for objects without id property', () => {
- expect(isApiProvider({})).toBe(false);
- expect(isApiProvider({ callApi: () => {} })).toBe(false);
- });
- it('should return false when id exists but is not a function', () => {
- expect(isApiProvider({ id: 'string' })).toBe(false);
- expect(isApiProvider({ id: 123 })).toBe(false);
- expect(isApiProvider({ id: true })).toBe(false);
- expect(isApiProvider({ id: {} })).toBe(false);
- expect(isApiProvider({ id: [] })).toBe(false);
- });
- });
- describe('isProviderOptions', () => {
- it('should correctly identify valid ProviderOptions objects', () => {
- const validOptions: ProviderOptions[] = [
- {
- id: 'test-provider',
- },
- {
- id: 'full-options',
- label: 'Test Provider',
- config: { temperature: 0.7 },
- prompts: ['Hello, {{name}}!'],
- transform: 'toLowerCase()',
- delay: 1000,
- env: { OPENAI_API_KEY: 'test-key' },
- },
- {
- id: 'minimal-options',
- },
- ];
- validOptions.forEach((options) => {
- expect(isProviderOptions(options)).toBe(true);
- });
- });
- it('should correctly identify invalid ProviderOptions objects', () => {
- const invalidOptions = [
- null,
- undefined,
- {},
- { id: undefined },
- { id: null },
- { id: 42 },
- { id: () => 'function-not-string' },
- { label: 'Missing ID' },
- 'string-options',
- 42,
- true,
- [],
- new Date(),
- ];
- invalidOptions.forEach((options) => {
- expect(isProviderOptions(options)).toBe(false);
- });
- });
- it('should handle edge cases', () => {
- const edgeCases = [
- { id: 'valid', extraField: 'ignored' },
- { id: 'valid', config: null },
- { id: 'valid', prompts: [] },
- { id: 'valid', delay: 0 },
- { id: 'valid', env: {} },
- ];
- edgeCases.forEach((options) => {
- expect(isProviderOptions(options)).toBe(true);
- });
- });
- it('should return false for non-object values', () => {
- expect(isProviderOptions('string')).toBe(false);
- expect(isProviderOptions(123)).toBe(false);
- expect(isProviderOptions(true)).toBe(false);
- expect(isProviderOptions(undefined)).toBe(false);
- expect(isProviderOptions(null)).toBe(false);
- });
- it('should return false for objects without id property', () => {
- expect(isProviderOptions({})).toBe(false);
- expect(isProviderOptions({ label: 'Test' })).toBe(false);
- });
- it('should return false when id exists but is not a string', () => {
- expect(isProviderOptions({ id: () => 'function' })).toBe(false);
- expect(isProviderOptions({ id: 123 })).toBe(false);
- expect(isProviderOptions({ id: true })).toBe(false);
- expect(isProviderOptions({ id: {} })).toBe(false);
- expect(isProviderOptions({ id: [] })).toBe(false);
- });
- });
|