/** * Port traits (interfaces) to external services. Mirrors `apps/application/src/ports/`. * Concrete implementations live in the infrastructure layer. */ import type { ChatMessage, StreamEvent, ToolDef } from "@zesdex/domain"; /** Abstraction for an LLM provider chat-completion service. */ export interface ProviderService { /** * Send a non-streaming chat completion request. * Returns the assistant's `ChatMessage` and optional `[prompt, completion]` token usage. */ chat( messages: ChatMessage[], tools?: ToolDef[], maxTokens?: number, temperature?: number, ): Promise<{ message: ChatMessage; usage: [number, number] | null }>; /** * Send a streaming request. `onEvent` is called per parsed SSE event and * returns `false` to abort. Returns the fully assembled assistant message * and optional usage once the stream completes. */ chatStream( messages: ChatMessage[], tools: ToolDef[], maxTokens: number, temperature: number, onEvent: (event: StreamEvent) => boolean, signal?: AbortSignal, ): Promise<{ message: ChatMessage; usage: [number, number] | null }>; } /** Abstraction for password hashing and verification. */ export interface PasswordService { hash(password: string): Promise; verify(password: string, hash: string): Promise; } /** Abstraction for JWT-based token generation and verification. */ export interface TokenService { /** Generate an `[access, refresh]` token pair for the given subject. */ generateTokens(sub: string): [string, string]; verifyAccessToken(token: string): string; verifyRefreshToken(token: string): string; } /** High-level authentication service combining password + token issuance. */ export interface AuthService { authenticate(password: string, hash: string): Promise; issueTokens(sub: string): [string, string]; }