tdd-guard
Version:
TDD Guard enforces Test-Driven Development principles using Claude Code hooks
43 lines (42 loc) • 1.36 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.AnthropicApi = void 0;
const sdk_1 = __importDefault(require("@anthropic-ai/sdk"));
const Config_1 = require("../../config/Config");
class AnthropicApi {
config;
client;
constructor(config) {
this.config = config ?? new Config_1.Config();
this.client = new sdk_1.default({
apiKey: this.config.anthropicApiKey,
});
}
async ask(prompt) {
const response = await this.client.messages.create({
model: 'claude-sonnet-4-20250514',
max_tokens: 1024,
messages: [
{
role: 'user',
content: prompt,
},
],
});
return extractTextFromResponse(response);
}
}
exports.AnthropicApi = AnthropicApi;
function extractTextFromResponse(response) {
if (response.content.length === 0) {
throw new Error('No content in response');
}
const firstContent = response.content[0];
if (!('text' in firstContent) || !firstContent.text) {
throw new Error('Response content does not contain text');
}
return firstContent.text;
}