neura-sdk
Version:
TypeScript SDK for interacting with the Neura AI API
59 lines (58 loc) • 1.69 kB
TypeScript
import { EventEmitter } from 'events';
export interface CompletionsRequestOptions {
messages: string;
sessionId?: string;
userId?: string;
fileData?: string | Buffer;
stream?: boolean;
reasoningFormat?: string;
}
export interface CompletionsResponse {
requestId: string;
response: string;
processingTimeMs: number;
}
export interface StreamChunk {
chunk: string;
requestId: string;
}
export interface ProcessingError {
error: string;
requestId: string;
code: string;
processingTimeMs: number;
}
export type NeuraResponse = CompletionsResponse | ProcessingError;
export interface NeuraSDKConfig {
baseUrl: string;
apiKey: string;
maxRetries?: number;
retryDelay?: number;
requestsPerMinute?: number;
enableCache?: boolean;
cacheTTL?: number;
}
export interface CacheOptions {
ttl: number;
}
export interface CacheEntry<T> {
value: T;
expires: number;
}
export interface CacheInterface {
get<T>(key: string): T | undefined;
set<T>(key: string, value: T, options?: Partial<CacheOptions>): void;
has(key: string): boolean;
delete(key: string): boolean;
clear(): void;
}
export interface NeuraStreamEvents {
chunk: (chunk: StreamChunk) => void;
done: () => void;
error: (error: Error | ProcessingError) => void;
}
export interface NeuraStream extends EventEmitter {
on<E extends keyof NeuraStreamEvents>(event: E, listener: NeuraStreamEvents[E]): this;
once<E extends keyof NeuraStreamEvents>(event: E, listener: NeuraStreamEvents[E]): this;
emit<E extends keyof NeuraStreamEvents>(event: E, ...args: Parameters<NeuraStreamEvents[E]>): boolean;
}