|
1 | 1 | // Test TypeScript type resolution in ESM environment |
2 | | -import type { CodebuffClient, CustomToolDefinition, RunState } from '@codebuff/sdk'; |
3 | | -import { CodebuffClient as ClientClass, getCustomToolDefinition } from '@codebuff/sdk'; |
4 | | -import * as FullSDK from '@codebuff/sdk'; |
5 | | - |
6 | | -(async () => { |
| 2 | +import type { |
| 3 | + CodebuffClient, |
| 4 | + CustomToolDefinition, |
| 5 | + RunState, |
| 6 | +} from '@codebuff/sdk' |
| 7 | +import { |
| 8 | + CodebuffClient as ClientClass, |
| 9 | + getCustomToolDefinition, |
| 10 | +} from '@codebuff/sdk' |
| 11 | +import * as FullSDK from '@codebuff/sdk' |
| 12 | + |
| 13 | +;(async () => { |
7 | 14 | // Test 1: Type imports work correctly |
8 | | - const testClient: CodebuffClient = {} as any; |
9 | | - const testTool: CustomToolDefinition = {} as any; |
10 | | - const testState: RunState = {} as any; |
| 15 | + const testClient: CodebuffClient = {} as any |
| 16 | + const testTool: CustomToolDefinition = {} as any |
| 17 | + const testState: RunState = {} as any |
11 | 18 |
|
12 | | - console.log('✅ Type imports successful'); |
| 19 | + console.log('✅ Type imports successful') |
13 | 20 |
|
14 | 21 | // Test 2: Value imports work correctly in TypeScript |
15 | | - const clientConstructor = ClientClass; |
16 | | - const toolDefFunction = getCustomToolDefinition; |
| 22 | + const clientConstructor = ClientClass |
| 23 | + const toolDefFunction = getCustomToolDefinition |
17 | 24 |
|
18 | | - console.log('✅ Value imports successful:', typeof clientConstructor, typeof toolDefFunction); |
| 25 | + console.log( |
| 26 | + '✅ Value imports successful:', |
| 27 | + typeof clientConstructor, |
| 28 | + typeof toolDefFunction, |
| 29 | + ) |
19 | 30 |
|
20 | 31 | // Test 3: Test actual instantiation would work (without requiring API key) |
21 | | - type ClientOptions = ConstructorParameters<typeof ClientClass>[0]; |
| 32 | + type ClientOptions = ConstructorParameters<typeof ClientClass>[0] |
22 | 33 |
|
23 | 34 | const mockOptions: ClientOptions = { |
24 | 35 | apiKey: 'test-key', |
25 | | - onError: (error) => console.error('Test error:', error.message), |
26 | | - }; |
| 36 | + } |
27 | 37 |
|
28 | 38 | // This should compile without errors |
29 | | - const mockClient = new ClientClass(mockOptions); |
| 39 | + const mockClient = new ClientClass(mockOptions) |
30 | 40 |
|
31 | | - console.log('✅ Client instantiation types work correctly'); |
| 41 | + console.log('✅ Client instantiation types work correctly') |
32 | 42 |
|
33 | 43 | // Test 4: Custom tool definition types (compile-time only) |
34 | | - type MockTool = ReturnType<typeof getCustomToolDefinition<'test-tool', any, any, any>>; |
35 | | - const toolTypeTest: MockTool = {} as any; |
| 44 | + type MockTool = ReturnType<typeof getCustomToolDefinition> |
| 45 | + const toolTypeTest: MockTool = {} as any |
36 | 46 |
|
37 | | - console.log('✅ Custom tool definition types work correctly'); |
| 47 | + console.log('✅ Custom tool definition types work correctly') |
38 | 48 |
|
39 | 49 | // Test 5: Dynamic imports also work in TypeScript ESM |
40 | | - const dynamicSDK = await import('@codebuff/sdk'); |
41 | | - const ClientFromDynamic: typeof ClientClass = dynamicSDK.CodebuffClient; |
42 | | - console.log('✅ Dynamic imports work in TypeScript ESM'); |
| 50 | + const dynamicSDK = await import('@codebuff/sdk') |
| 51 | + const ClientFromDynamic: typeof ClientClass = dynamicSDK.CodebuffClient |
| 52 | + console.log('✅ Dynamic imports work in TypeScript ESM') |
43 | 53 |
|
44 | 54 | // Test 6: Namespace imports work |
45 | | - const ClientFromNamespace: typeof ClientClass = FullSDK.CodebuffClient; |
46 | | - console.log('✅ Namespace imports work correctly'); |
47 | | -})(); |
| 55 | + const ClientFromNamespace: typeof ClientClass = FullSDK.CodebuffClient |
| 56 | + console.log('✅ Namespace imports work correctly') |
| 57 | +})() |
48 | 58 |
|
49 | | -export {}; // Make this a module |
| 59 | +export {} // Make this a module |
0 commit comments