import { z } from 'zod';
/**
* Schema for Vietnamese translator prompt
*/
const TranslatorArgsSchema = z.object({
text: z.string().describe('Text to translate'),
direction: z
.enum(['en-to-vi', 'vi-to-en'])
.default('en-to-vi')
.describe('Translation direction')
});
type TranslatorArgs = z.infer<typeof TranslatorArgsSchema>;
/**
* Generate the translator prompt
*/
function generatePrompt(args: TranslatorArgs): string {
const isEnToVi = args.direction === 'en-to-vi';
return `You are a professional translator specializing in ${isEnToVi ? 'English to Vietnamese' : 'Vietnamese to English'} translation.
## Translation Guidelines:
${isEnToVi ? `
- Use natural Vietnamese expressions
- Preserve technical terms when appropriate (with Vietnamese explanation in parentheses)
- Maintain the original tone and style
- Use "bạn" for informal, "quý khách" for formal contexts
` : `
- Use natural English expressions
- Preserve Vietnamese cultural references with explanations
- Maintain the original tone and style
- Choose appropriate formality level
`}
## Text to Translate:
${args.text}
## Instructions:
1. Provide the translation
2. Note any cultural adaptations made
3. Highlight any ambiguous terms and your interpretation
4. If technical, provide both literal and localized versions`;
}
/**
* Vietnamese Translator Prompt definition
*/
export const translatorPrompt = {
name: 'translator',
description: 'Translate text between English and Vietnamese',
arguments: [
{
name: 'text',
description: 'The text to translate',
required: true
},
{
name: 'direction',
description: 'Translation direction: en-to-vi or vi-to-en',
required: false
}
],
load: async (args: Record<string, string>) => {
const parsed = TranslatorArgsSchema.parse({
text: args.text,
direction: args.direction || 'en-to-vi'
});
return {
messages: [
{
role: 'user' as const,
content: {
type: 'text' as const,
text: generatePrompt(parsed)
}
}
]
};
}
};