32 lines
916 B
TypeScript
32 lines
916 B
TypeScript
import Anthropic from '@anthropic-ai/sdk';
|
|
|
|
/**
|
|
* Thin wrapper around the Anthropic SDK.
|
|
* Handles initialisation and raw message completion only —
|
|
* prompt construction and response parsing stay in LLMAnalyst (service layer).
|
|
*/
|
|
export class AnthropicClient {
|
|
private client: Anthropic | null;
|
|
|
|
constructor() {
|
|
this.client = process.env.ANTHROPIC_API_KEY
|
|
? new Anthropic({ apiKey: process.env.ANTHROPIC_API_KEY })
|
|
: null;
|
|
}
|
|
|
|
get isAvailable(): boolean {
|
|
return this.client !== null;
|
|
}
|
|
|
|
async complete(system: string, userMessage: string): Promise<string | null> {
|
|
if (!this.client) return null;
|
|
const response = await this.client.messages.create({
|
|
model: 'claude-haiku-4-5-20251001',
|
|
max_tokens: 1024,
|
|
system,
|
|
messages: [{ role: 'user', content: userMessage }],
|
|
});
|
|
return (response.content[0] as { text?: string })?.text ?? null;
|
|
}
|
|
}
|