140 lines
		
	
	
		
			4.2 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
		
		
			
		
	
	
			140 lines
		
	
	
		
			4.2 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
| 
								 | 
							
								import { tap, expect } from '@push.rocks/tapbundle';
							 | 
						||
| 
								 | 
							
								import * as smartai from '../ts/index.js';
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								// Test interface exports and type checking
							 | 
						||
| 
								 | 
							
								// These tests verify that all interfaces are properly exported and usable
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								tap.test('Interfaces: ResearchOptions should be properly typed', async () => {
							 | 
						||
| 
								 | 
							
								  const testOptions: smartai.ResearchOptions = {
							 | 
						||
| 
								 | 
							
								    query: 'test query',
							 | 
						||
| 
								 | 
							
								    searchDepth: 'basic',
							 | 
						||
| 
								 | 
							
								    maxSources: 10,
							 | 
						||
| 
								 | 
							
								    includeWebSearch: true,
							 | 
						||
| 
								 | 
							
								    background: false
							 | 
						||
| 
								 | 
							
								  };
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								  expect(testOptions).toBeInstanceOf(Object);
							 | 
						||
| 
								 | 
							
								  expect(testOptions.query).toEqual('test query');
							 | 
						||
| 
								 | 
							
								  expect(testOptions.searchDepth).toEqual('basic');
							 | 
						||
| 
								 | 
							
								});
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								tap.test('Interfaces: ResearchResponse should be properly typed', async () => {
							 | 
						||
| 
								 | 
							
								  const testResponse: smartai.ResearchResponse = {
							 | 
						||
| 
								 | 
							
								    answer: 'test answer',
							 | 
						||
| 
								 | 
							
								    sources: [
							 | 
						||
| 
								 | 
							
								      {
							 | 
						||
| 
								 | 
							
								        url: 'https://example.com',
							 | 
						||
| 
								 | 
							
								        title: 'Example Source',
							 | 
						||
| 
								 | 
							
								        snippet: 'This is a snippet'
							 | 
						||
| 
								 | 
							
								      }
							 | 
						||
| 
								 | 
							
								    ],
							 | 
						||
| 
								 | 
							
								    searchQueries: ['query1', 'query2'],
							 | 
						||
| 
								 | 
							
								    metadata: {
							 | 
						||
| 
								 | 
							
								      model: 'test-model',
							 | 
						||
| 
								 | 
							
								      tokensUsed: 100
							 | 
						||
| 
								 | 
							
								    }
							 | 
						||
| 
								 | 
							
								  };
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								  expect(testResponse).toBeInstanceOf(Object);
							 | 
						||
| 
								 | 
							
								  expect(testResponse.answer).toEqual('test answer');
							 | 
						||
| 
								 | 
							
								  expect(testResponse.sources).toBeArray();
							 | 
						||
| 
								 | 
							
								  expect(testResponse.sources[0].url).toEqual('https://example.com');
							 | 
						||
| 
								 | 
							
								});
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								tap.test('Interfaces: ChatOptions should be properly typed', async () => {
							 | 
						||
| 
								 | 
							
								  const testChatOptions: smartai.ChatOptions = {
							 | 
						||
| 
								 | 
							
								    systemMessage: 'You are a helpful assistant',
							 | 
						||
| 
								 | 
							
								    userMessage: 'Hello',
							 | 
						||
| 
								 | 
							
								    messageHistory: [
							 | 
						||
| 
								 | 
							
								      { role: 'user', content: 'Previous message' },
							 | 
						||
| 
								 | 
							
								      { role: 'assistant', content: 'Previous response' }
							 | 
						||
| 
								 | 
							
								    ]
							 | 
						||
| 
								 | 
							
								  };
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								  expect(testChatOptions).toBeInstanceOf(Object);
							 | 
						||
| 
								 | 
							
								  expect(testChatOptions.systemMessage).toBeTruthy();
							 | 
						||
| 
								 | 
							
								  expect(testChatOptions.messageHistory).toBeArray();
							 | 
						||
| 
								 | 
							
								});
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								tap.test('Interfaces: ChatResponse should be properly typed', async () => {
							 | 
						||
| 
								 | 
							
								  const testChatResponse: smartai.ChatResponse = {
							 | 
						||
| 
								 | 
							
								    role: 'assistant',
							 | 
						||
| 
								 | 
							
								    message: 'This is a response'
							 | 
						||
| 
								 | 
							
								  };
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								  expect(testChatResponse).toBeInstanceOf(Object);
							 | 
						||
| 
								 | 
							
								  expect(testChatResponse.role).toEqual('assistant');
							 | 
						||
| 
								 | 
							
								  expect(testChatResponse.message).toBeTruthy();
							 | 
						||
| 
								 | 
							
								});
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								tap.test('Interfaces: ChatMessage should be properly typed', async () => {
							 | 
						||
| 
								 | 
							
								  const testMessage: smartai.ChatMessage = {
							 | 
						||
| 
								 | 
							
								    role: 'user',
							 | 
						||
| 
								 | 
							
								    content: 'Test message'
							 | 
						||
| 
								 | 
							
								  };
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								  expect(testMessage).toBeInstanceOf(Object);
							 | 
						||
| 
								 | 
							
								  expect(testMessage.role).toBeOneOf(['user', 'assistant', 'system']);
							 | 
						||
| 
								 | 
							
								  expect(testMessage.content).toBeTruthy();
							 | 
						||
| 
								 | 
							
								});
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								tap.test('Interfaces: Provider options should be properly typed', async () => {
							 | 
						||
| 
								 | 
							
								  // OpenAI options
							 | 
						||
| 
								 | 
							
								  const openaiOptions: smartai.IOpenaiProviderOptions = {
							 | 
						||
| 
								 | 
							
								    openaiToken: 'test-token',
							 | 
						||
| 
								 | 
							
								    chatModel: 'gpt-5-mini',
							 | 
						||
| 
								 | 
							
								    audioModel: 'tts-1-hd',
							 | 
						||
| 
								 | 
							
								    visionModel: '04-mini',
							 | 
						||
| 
								 | 
							
								    researchModel: 'o4-mini-deep-research-2025-06-26',
							 | 
						||
| 
								 | 
							
								    enableWebSearch: true
							 | 
						||
| 
								 | 
							
								  };
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								  expect(openaiOptions).toBeInstanceOf(Object);
							 | 
						||
| 
								 | 
							
								  expect(openaiOptions.openaiToken).toBeTruthy();
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								  // Anthropic options
							 | 
						||
| 
								 | 
							
								  const anthropicOptions: smartai.IAnthropicProviderOptions = {
							 | 
						||
| 
								 | 
							
								    anthropicToken: 'test-token',
							 | 
						||
| 
								 | 
							
								    enableWebSearch: true,
							 | 
						||
| 
								 | 
							
								    searchDomainAllowList: ['example.com'],
							 | 
						||
| 
								 | 
							
								    searchDomainBlockList: ['blocked.com']
							 | 
						||
| 
								 | 
							
								  };
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								  expect(anthropicOptions).toBeInstanceOf(Object);
							 | 
						||
| 
								 | 
							
								  expect(anthropicOptions.anthropicToken).toBeTruthy();
							 | 
						||
| 
								 | 
							
								});
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								tap.test('Interfaces: Search depth values should be valid', async () => {
							 | 
						||
| 
								 | 
							
								  const validDepths: smartai.ResearchOptions['searchDepth'][] = ['basic', 'advanced', 'deep'];
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								  for (const depth of validDepths) {
							 | 
						||
| 
								 | 
							
								    const options: smartai.ResearchOptions = {
							 | 
						||
| 
								 | 
							
								      query: 'test',
							 | 
						||
| 
								 | 
							
								      searchDepth: depth
							 | 
						||
| 
								 | 
							
								    };
							 | 
						||
| 
								 | 
							
								    expect(options.searchDepth).toBeOneOf(['basic', 'advanced', 'deep', undefined]);
							 | 
						||
| 
								 | 
							
								  }
							 | 
						||
| 
								 | 
							
								});
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								tap.test('Interfaces: Optional properties should work correctly', async () => {
							 | 
						||
| 
								 | 
							
								  // Minimal ResearchOptions
							 | 
						||
| 
								 | 
							
								  const minimalOptions: smartai.ResearchOptions = {
							 | 
						||
| 
								 | 
							
								    query: 'test query'
							 | 
						||
| 
								 | 
							
								  };
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								  expect(minimalOptions.query).toBeTruthy();
							 | 
						||
| 
								 | 
							
								  expect(minimalOptions.searchDepth).toBeUndefined();
							 | 
						||
| 
								 | 
							
								  expect(minimalOptions.maxSources).toBeUndefined();
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								  // Minimal ChatOptions
							 | 
						||
| 
								 | 
							
								  const minimalChat: smartai.ChatOptions = {
							 | 
						||
| 
								 | 
							
								    systemMessage: 'system',
							 | 
						||
| 
								 | 
							
								    userMessage: 'user',
							 | 
						||
| 
								 | 
							
								    messageHistory: []
							 | 
						||
| 
								 | 
							
								  };
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								  expect(minimalChat.messageHistory).toBeArray();
							 | 
						||
| 
								 | 
							
								  expect(minimalChat.messageHistory.length).toEqual(0);
							 | 
						||
| 
								 | 
							
								});
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								export default tap.start();
							 |