Implements 10 MCP tools for task management: - CRUD: task_add, task_list, task_show, task_close, task_update - Search: task_similar (pgvector), task_context - Relations: task_link, task_checklist_add, task_checklist_toggle Uses PostgreSQL with pgvector for semantic search via LiteLLM embeddings. Connects via SSH tunnel to docker-host:5435. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
59 lines
1.4 KiB
TypeScript
59 lines
1.4 KiB
TypeScript
// Embeddings via LiteLLM API
|
|
|
|
const LLM_API_URL = process.env.LLM_API_URL || 'https://llm.agiliton.cloud';
|
|
const LLM_API_KEY = process.env.LLM_API_KEY || '';
|
|
|
|
interface EmbeddingResponse {
|
|
data: Array<{
|
|
embedding: number[];
|
|
index: number;
|
|
}>;
|
|
model: string;
|
|
usage: {
|
|
prompt_tokens: number;
|
|
total_tokens: number;
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Generate embedding for text using LiteLLM API
|
|
*/
|
|
export async function getEmbedding(text: string): Promise<number[] | null> {
|
|
if (!LLM_API_KEY) {
|
|
console.error('LLM_API_KEY not set, skipping embedding');
|
|
return null;
|
|
}
|
|
|
|
try {
|
|
const response = await fetch(`${LLM_API_URL}/v1/embeddings`, {
|
|
method: 'POST',
|
|
headers: {
|
|
'Authorization': `Bearer ${LLM_API_KEY}`,
|
|
'Content-Type': 'application/json',
|
|
},
|
|
body: JSON.stringify({
|
|
model: 'text-embedding-ada-002',
|
|
input: text,
|
|
}),
|
|
});
|
|
|
|
if (!response.ok) {
|
|
console.error('Embedding API error:', response.status, await response.text());
|
|
return null;
|
|
}
|
|
|
|
const data = await response.json() as EmbeddingResponse;
|
|
return data.data?.[0]?.embedding || null;
|
|
} catch (error) {
|
|
console.error('Embedding generation failed:', error);
|
|
return null;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Format embedding array for PostgreSQL vector type
|
|
*/
|
|
export function formatEmbedding(embedding: number[]): string {
|
|
return `[${embedding.join(',')}]`;
|
|
}
|