opus-client.tsā¢1.57 kB
import Anthropic from '@anthropic-ai/sdk';
import type { ShortcutData } from './types.js';
export class OpusClient {
private client: Anthropic;
constructor(apiKey?: string) {
this.client = new Anthropic({
apiKey: apiKey || process.env.ANTHROPIC_API_KEY
});
}
async queryShortcuts(query: string, relevantData: ShortcutData[]): Promise<string> {
const dataContext = JSON.stringify(relevantData, null, 2);
const systemPrompt = `You are a keyboard shortcuts expert. You have access to a database of keyboard shortcuts for various operating systems, desktop environments, and applications.
The user will ask you about keyboard shortcuts, and you must search through the provided data to find the most relevant shortcuts.
IMPORTANT: Only return shortcuts that exist in the provided data. Do not make up or assume shortcuts.
Format your response as a clear, concise list of relevant shortcuts with their descriptions.`;
const userPrompt = `Here is the shortcuts database for the requested context:
${dataContext}
User query: ${query}
Please provide the relevant keyboard shortcuts from the data above.`;
const response = await this.client.messages.create({
model: 'claude-opus-4-20250514',
max_tokens: 4096,
system: systemPrompt,
messages: [
{
role: 'user',
content: userPrompt
}
]
});
const textContent = response.content.find(block => block.type === 'text');
return textContent?.type === 'text' ? textContent.text : 'No response generated';
}
}