fix(emoji-magic): add defensive checks for missing required parameters

- Add validation in both textToEmoji and emojiMood to handle missing text parameter
- Return descriptive error instead of crashing with undefined error
- Bump to v0.2.1
This commit is contained in:
Ajax Davis 2025-12-05 00:51:24 +10:00
parent 47577a43e5
commit 0c7b058593
3 changed files with 25 additions and 1 deletions

View file

@ -1,6 +1,6 @@
{
"name": "@tpmjs/emoji-magic",
"version": "0.2.0",
"version": "0.2.1",
"description": "AI SDK tools for emoji-magic - convert text to emojis and back!",
"type": "module",
"main": "dist/index.js",

View file

@ -15,6 +15,18 @@ export const emojiMood = tool({
async execute(input: z.infer<typeof EmojiMoodSchema>) {
const { text, count } = input;
// Validate required parameters (defensive check)
if (!text) {
return {
success: false,
error: 'Missing required parameter: text',
mood: 'unknown',
suggestions: [],
text_length: 0,
analysis: 'Cannot analyze mood without text input',
};
}
// Simple sentiment analysis based on keywords
const positiveWords = [
'happy',

View file

@ -18,6 +18,18 @@ export const textToEmoji = tool({
async execute(input: z.infer<typeof TextToEmojiSchema>) {
const { text, style } = input;
// Validate required parameters (defensive check)
if (!text) {
return {
success: false,
error: 'Missing required parameter: text',
original: '',
converted: '',
style,
emoji_count: 0,
};
}
// Simple word-to-emoji mappings
const emojiMap: Record<string, string> = {
// Emotions