feature: port from python client lib

This commit is contained in:
Alpha Nerd 2026-01-17 12:02:08 +01:00
parent 129c6cd004
commit fd1a3b50cb
29 changed files with 3141 additions and 2 deletions

105
src/types/api.ts Normal file
View file

@ -0,0 +1,105 @@
/**
* OpenAI-compatible API type definitions
* These types match the OpenAI Chat Completion API for full compatibility
*/
export interface Message {
role: 'system' | 'user' | 'assistant' | 'tool';
content?: string;
name?: string;
tool_calls?: ToolCall[];
tool_call_id?: string;
}
export interface ToolCall {
id: string;
type: 'function';
function: {
name: string;
arguments: string;
};
}
export interface FunctionDefinition {
name: string;
description?: string;
parameters?: object;
}
export interface Tool {
type: 'function';
function: FunctionDefinition;
}
export type ToolChoice = 'none' | 'auto' | 'required' | { type: 'function'; function: { name: string } };
export interface ChatCompletionRequest {
model: string;
messages: Message[];
// Optional parameters (matching OpenAI API)
temperature?: number;
top_p?: number;
n?: number;
stream?: boolean;
stop?: string | string[];
max_tokens?: number;
presence_penalty?: number;
frequency_penalty?: number;
logit_bias?: Record<string, number>;
user?: string;
// Tool/Function calling
tools?: Tool[];
tool_choice?: ToolChoice;
// Additional parameters
[key: string]: unknown;
}
export interface Usage {
prompt_tokens: number;
completion_tokens: number;
total_tokens: number;
}
export interface Choice {
index: number;
message: Message;
finish_reason: 'stop' | 'length' | 'tool_calls' | 'content_filter' | null;
logprobs?: unknown;
}
export interface ResponseMetadata {
payload_id: string;
processed_at: number;
is_encrypted: boolean;
encryption_algorithm: string;
response_status: string;
}
export interface ChatCompletionResponse {
id: string;
object: 'chat.completion';
created: number;
model: string;
choices: Choice[];
usage?: Usage;
system_fingerprint?: string;
// NOMYO-specific metadata
_metadata?: ResponseMetadata;
}
// Streaming types (for future implementation)
export interface ChatCompletionChunk {
id: string;
object: 'chat.completion.chunk';
created: number;
model: string;
choices: {
index: number;
delta: Partial<Message>;
finish_reason: string | null;
}[];
}

56
src/types/client.ts Normal file
View file

@ -0,0 +1,56 @@
/**
* Client configuration types
*/
export interface ClientConfig {
/** Base URL of the NOMYO router (e.g., https://api.nomyo.ai:12434) */
routerUrl: string;
/** Allow HTTP connections (ONLY for local development, never in production) */
allowHttp?: boolean;
/** Enable secure memory protection (zeroing) */
secureMemory?: boolean;
/** RSA key size in bits (2048 or 4096) */
keySize?: 2048 | 4096;
/** Optional API key for authentication */
apiKey?: string;
}
export interface KeyGenOptions {
/** RSA key size in bits */
keySize?: 2048 | 4096;
/** Save keys to file system (Node.js only) */
saveToFile?: boolean;
/** Directory to save keys (default: 'client_keys') */
keyDir?: string;
/** Password to encrypt private key (recommended for production) */
password?: string;
}
export interface KeyPaths {
/** Path to private key file */
privateKeyPath: string;
/** Path to public key file (optional, will derive from private key path) */
publicKeyPath?: string;
}
export interface ChatCompletionConfig {
/** Base URL of the NOMYO router */
baseUrl?: string;
/** Allow HTTP connections */
allowHttp?: boolean;
/** API key for authentication */
apiKey?: string;
/** Enable secure memory protection */
secureMemory?: boolean;
}

42
src/types/crypto.ts Normal file
View file

@ -0,0 +1,42 @@
/**
* Cryptography-related types
*/
export interface EncryptedPackage {
/** Encrypted payload data */
encrypted_payload: string;
/** Encrypted AES key (encrypted with server's RSA public key) */
encrypted_aes_key: string;
/** Client's public key in PEM format */
client_public_key: string;
/** Unique identifier for this encrypted package */
payload_id: string;
/** Nonce/IV used for AES encryption (base64 encoded) */
nonce: string;
}
export interface ProtectionInfo {
/** Whether memory can be locked (mlock) */
canLock: boolean;
/** Whether the platform provides secure memory protection */
isPlatformSecure: boolean;
/** Method used for memory protection */
method: 'mlock' | 'zero-only' | 'none';
/** Additional information about protection status */
details?: string;
}
export interface SecureMemoryConfig {
/** Enable secure memory protection */
enabled: boolean;
/** Prefer native addon if available (Node.js only) */
preferNative?: boolean;
}