@xuda.io/ai_module 1.1.4641 → 1.1.4642

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.mjs +479 -0
  2. package/package.json +1 -1
package/index.mjs CHANGED
@@ -7749,3 +7749,482 @@ function getDomainFromCategory(category) {
7749
7749
  }
7750
7750
  return 'General';
7751
7751
  }
7752
+
7753
+ export const categorize_text_message = async function (uid, message_text, contact_info, metadata = {}) {
7754
+ const text_message_categories = [
7755
+ // Personal Communication (1-20)
7756
+ 'Casual Conversation',
7757
+ 'Catching Up',
7758
+ 'Daily Check-in',
7759
+ 'Family Update',
7760
+ 'Friend Chat',
7761
+ 'Romantic Message',
7762
+ 'Flirting / Dating',
7763
+ 'Expressing Feelings',
7764
+ 'Emotional Support',
7765
+ 'Comfort / Consolation',
7766
+ 'Congratulations',
7767
+ 'Sympathy / Condolences',
7768
+ 'Birthday Wishes',
7769
+ 'Holiday Greetings',
7770
+ 'Anniversary Message',
7771
+ 'Thank You Message',
7772
+ 'Apology Message',
7773
+ 'Forgiveness Request',
7774
+ 'Miss You Message',
7775
+ 'Thinking of You',
7776
+
7777
+ // Practical & Logistics (21-40)
7778
+ 'Meeting Coordination',
7779
+ 'Plans Making',
7780
+ 'Schedule Coordination',
7781
+ 'Time Confirmation',
7782
+ 'Location Sharing',
7783
+ 'Address Request',
7784
+ 'Directions Request',
7785
+ 'Ride Coordination',
7786
+ 'Pickup Request',
7787
+ 'Drop-off Arrangement',
7788
+ 'Event Details',
7789
+ 'Reservation Confirmation',
7790
+ 'Travel Coordination',
7791
+ 'Running Late Notification',
7792
+ 'Change of Plans',
7793
+ 'Cancellation Notice',
7794
+ 'Reminder Sent',
7795
+ 'Follow-up Request',
7796
+ 'Confirmation Needed',
7797
+ 'Status Update',
7798
+
7799
+ // Information Exchange (41-60)
7800
+ 'Question Asking',
7801
+ 'Information Request',
7802
+ 'Advice Seeking',
7803
+ 'Opinion Request',
7804
+ 'Recommendation Ask',
7805
+ 'Resource Sharing',
7806
+ 'Link Sharing',
7807
+ 'Photo Sharing',
7808
+ 'Video Sharing',
7809
+ 'Document Sharing',
7810
+ 'News Sharing',
7811
+ 'Article Forwarding',
7812
+ 'Meme Sharing',
7813
+ 'Joke Sharing',
7814
+ 'Interesting Fact',
7815
+ 'Tip Sharing',
7816
+ 'Recipe Sharing',
7817
+ 'Book/Movie Recommendation',
7818
+ 'Music Recommendation',
7819
+ 'Restaurant Suggestion',
7820
+
7821
+ // Work & Business (61-75)
7822
+ 'Work Discussion',
7823
+ 'Project Update',
7824
+ 'Task Assignment',
7825
+ 'Deadline Reminder',
7826
+ 'Client Communication',
7827
+ 'Colleague Coordination',
7828
+ 'Team Collaboration',
7829
+ 'Business Inquiry',
7830
+ 'Professional Networking',
7831
+ 'Interview Coordination',
7832
+ 'Job Opportunity',
7833
+ 'Business Idea',
7834
+ 'Partnership Discussion',
7835
+ 'Contract Details',
7836
+ 'Payment Discussion',
7837
+
7838
+ // Urgent & Emergency (76-85)
7839
+ 'Emergency Alert',
7840
+ 'Help Request',
7841
+ 'Urgent Assistance',
7842
+ 'Safety Check',
7843
+ 'Medical Emergency',
7844
+ 'Accident Report',
7845
+ 'Lost Item Report',
7846
+ 'Security Concern',
7847
+ 'Immediate Response Needed',
7848
+ 'Critical Update',
7849
+
7850
+ // Social & Invitations (86-95)
7851
+ 'Event Invitation',
7852
+ 'Party Invite',
7853
+ 'Gathering Plan',
7854
+ 'Dinner Invitation',
7855
+ 'Movie Night Plan',
7856
+ 'Game Night',
7857
+ 'Weekend Plans',
7858
+ 'Hangout Request',
7859
+ 'Social Media Tag',
7860
+ 'Group Chat Add',
7861
+
7862
+ // Shopping & Commerce (96-105)
7863
+ 'Purchase Inquiry',
7864
+ 'Product Question',
7865
+ 'Price Check',
7866
+ 'Shopping Coordination',
7867
+ 'Gift Idea',
7868
+ 'Order Status',
7869
+ 'Delivery Update',
7870
+ 'Payment Request',
7871
+ 'Bill Splitting',
7872
+ 'Money Transfer',
7873
+
7874
+ // Health & Wellness (106-115)
7875
+ 'Health Update',
7876
+ 'Doctor Appointment',
7877
+ 'Medication Reminder',
7878
+ 'Wellness Check',
7879
+ 'Exercise Plan',
7880
+ 'Diet Discussion',
7881
+ 'Mental Health Check',
7882
+ 'Self-care Reminder',
7883
+ 'Recovery Update',
7884
+ 'Health Advice',
7885
+
7886
+ // Household & Family (116-125)
7887
+ 'Family Planning',
7888
+ 'Childcare Coordination',
7889
+ 'Pet Care',
7890
+ 'Home Maintenance',
7891
+ 'Grocery List',
7892
+ 'Chore Assignment',
7893
+ 'Household Decision',
7894
+ 'Property Discussion',
7895
+ 'Neighbor Communication',
7896
+ 'Community Update',
7897
+
7898
+ // Education & Learning (126-135)
7899
+ 'Homework Help',
7900
+ 'Study Group',
7901
+ 'Class Discussion',
7902
+ 'Assignment Reminder',
7903
+ 'School Update',
7904
+ 'Teacher Communication',
7905
+ 'Tutoring Request',
7906
+ 'Educational Resource',
7907
+ 'Learning Progress',
7908
+ 'Academic Achievement',
7909
+
7910
+ // Entertainment & Leisure (136-145)
7911
+ 'Game Invitation',
7912
+ 'Streaming Watch Party',
7913
+ 'Concert Plans',
7914
+ 'Sports Discussion',
7915
+ 'Hobby Sharing',
7916
+ 'Vacation Planning',
7917
+ 'Weekend Getaway',
7918
+ 'Adventure Plan',
7919
+ 'Outdoor Activity',
7920
+ 'Cultural Event',
7921
+
7922
+ // Technology & Digital (146-155)
7923
+ 'Tech Support',
7924
+ 'App Recommendation',
7925
+ 'Software Question',
7926
+ 'Device Issue',
7927
+ 'Password Reset',
7928
+ 'Account Recovery',
7929
+ 'Digital Security',
7930
+ 'Social Media Tagging',
7931
+ 'Online Purchase',
7932
+ 'Digital Content Share',
7933
+
7934
+ // Legal & Official (156-160)
7935
+ 'Legal Advice',
7936
+ 'Document Request',
7937
+ 'Official Notification',
7938
+ 'Government Matter',
7939
+ 'Compliance Issue',
7940
+
7941
+ // Spiritual & Religious (161-165)
7942
+ 'Prayer Request',
7943
+ 'Religious Event',
7944
+ 'Spiritual Guidance',
7945
+ 'Meditation Group',
7946
+ 'Faith Discussion',
7947
+
7948
+ // Miscellaneous (166-175)
7949
+ 'Random Thought',
7950
+ 'Philosophical Question',
7951
+ 'Deep Conversation',
7952
+ 'Hypothetical Scenario',
7953
+ 'Dream Sharing',
7954
+ 'Memory Recall',
7955
+ 'Future Planning',
7956
+ 'Goal Setting',
7957
+ 'Life Update',
7958
+ 'General Chat',
7959
+
7960
+ // Signal & Meta Communication (176-185)
7961
+ 'Read Receipt',
7962
+ 'Typing Indicator',
7963
+ 'Message Reaction',
7964
+ 'Voice Message',
7965
+ 'Video Call Request',
7966
+ 'Phone Call Follow-up',
7967
+ 'Connection Test',
7968
+ 'Network Issue',
7969
+ 'Delivery Failure',
7970
+ 'Message Forward',
7971
+
7972
+ // Relationship Dynamics (186-195)
7973
+ 'Conflict Resolution',
7974
+ 'Relationship Discussion',
7975
+ 'Boundary Setting',
7976
+ 'Expectation Setting',
7977
+ 'Commitment Talk',
7978
+ 'Future Plans Talk',
7979
+ 'Family Introduction',
7980
+ 'Meeting Planning',
7981
+ 'Relationship Milestone',
7982
+ 'Breakup Discussion',
7983
+
7984
+ // Quick & Brief (196-200)
7985
+ 'One-word Response',
7986
+ 'Emoji Message',
7987
+ 'Sticker/GIF Send',
7988
+ 'Quick Reply',
7989
+ 'Acknowledgment Only',
7990
+ ];
7991
+ const prompt = `Categorize the text message into one of these exact categories:
7992
+
7993
+ Text Message: "${message_text.substring(0, 300)}${message_text.length > 300 ? '...' : ''}"
7994
+
7995
+ Contact Context:
7996
+ - Relationship: ${contact_info?.relationship || 'Unknown'}
7997
+ - Frequency: ${metadata?.message_frequency || 'Unknown'}
7998
+ - Time of Day: ${new Date().getHours()}h
7999
+ - Previous Context: ${metadata?.previous_topic || 'Not provided'}
8000
+
8001
+ Available Categories (200 total):
8002
+ ${text_message_categories
8003
+ .slice(0, 25)
8004
+ .map((cat, index) => `${index + 1}. ${cat}`)
8005
+ .join('\n')}
8006
+ [Full list of 200 categories available to the system]
8007
+
8008
+ Instructions:
8009
+ 1. Analyze the message content, tone, and context
8010
+ 2. Consider the relationship between sender and recipient
8011
+ 3. Identify the primary purpose of the message
8012
+ 4. Choose the single most relevant category
8013
+ 5. Return only the exact category name
8014
+ 6. Factor in:
8015
+ - Urgency level
8016
+ - Emotional tone
8017
+ - Relationship context
8018
+ - Time sensitivity
8019
+ - Expected response type
8020
+ 7. If unsure, consider the most common interpretation
8021
+ 8. For ambiguous messages, choose based on typical usage patterns
8022
+
8023
+ Category:`;
8024
+
8025
+ try {
8026
+ const message_category_ret = await submit_chat_gpt_prompt({
8027
+ uid,
8028
+ prompt: prompt,
8029
+ model: 'gpt-4o-mini', // Good for short text analysis
8030
+ response_format: z.object({
8031
+ message_category: z.enum(text_message_categories),
8032
+ confidence_score: z.number().min(0).max(100),
8033
+ emotional_tone: z.enum(['Positive', 'Neutral', 'Negative', 'Mixed', 'Urgent', 'Playful', 'Formal', 'Casual']),
8034
+ urgency_level: z.enum(['Low', 'Medium', 'High', 'Emergency']),
8035
+ expected_response: z.enum(['None', 'Acknowledgment', 'Short Reply', 'Detailed Reply', 'Action Required', 'Immediate Call']),
8036
+ relationship_dynamics: z.string().max(100).optional(),
8037
+ }),
8038
+ metadata: {
8039
+ func: 'categorize_text_message',
8040
+ message_length: message_text.length,
8041
+ message_type: metadata?.is_media ? 'Multimedia' : 'Text Only',
8042
+ contact_relationship: contact_info?.relationship,
8043
+ time_sent: new Date().toISOString(),
8044
+ platform: metadata?.platform || 'Unknown',
8045
+ is_group_chat: metadata?.is_group_chat || false,
8046
+ },
8047
+ account_profile_info,
8048
+ });
8049
+
8050
+ if (message_category_ret && message_category_ret.code > -1) {
8051
+ const data = typeof message_category_ret.data === 'string' ? JSON.parse(message_category_ret.data) : message_category_ret.data;
8052
+
8053
+ // Analyze message characteristics
8054
+ const message_analysis = analyzeMessageCharacteristics(message_text, data.message_category);
8055
+
8056
+ // Determine priority for notification systems
8057
+ const priority_level = calculateMessagePriority(data.urgency_level, data.message_category, contact_info?.relationship);
8058
+
8059
+ return {
8060
+ success: true,
8061
+ category: data.message_category,
8062
+ confidence: data.confidence_score,
8063
+ emotional_tone: data.emotional_tone,
8064
+ urgency: data.urgency_level,
8065
+ expected_response: data.expected_response,
8066
+ priority: priority_level,
8067
+ relationship_dynamics: data.relationship_dynamics,
8068
+
8069
+ // Analysis results
8070
+ word_count: message_analysis.word_count,
8071
+ contains_questions: message_analysis.contains_questions,
8072
+ contains_requests: message_analysis.contains_requests,
8073
+ time_sensitive: message_analysis.time_sensitive,
8074
+
8075
+ // Context
8076
+ relationship: contact_info?.relationship || 'Unknown',
8077
+ typical_response_time: estimateResponseTime(data.message_category, contact_info?.relationship),
8078
+
8079
+ // Metadata
8080
+ message_preview: message_text.substring(0, 150),
8081
+ timestamp: new Date().toISOString(),
8082
+
8083
+ // Suggestions
8084
+ auto_reply_suggestion: generateAutoReplySuggestion(data.message_category, data.emotional_tone),
8085
+ follow_up_reminder: shouldScheduleFollowUp(data.message_category, data.urgency_level),
8086
+ };
8087
+ } else {
8088
+ return {
8089
+ success: false,
8090
+ category: 'General Chat',
8091
+ confidence: 0,
8092
+ emotional_tone: 'Neutral',
8093
+ urgency: 'Low',
8094
+ priority: 3,
8095
+ message_preview: message_text.substring(0, 150),
8096
+ error: message_category_ret?.message || 'API call failed',
8097
+ timestamp: new Date().toISOString(),
8098
+ };
8099
+ }
8100
+ } catch (error) {
8101
+ console.error('Error in categorize_text_message:', error);
8102
+ return {
8103
+ success: false,
8104
+ category: 'General Chat',
8105
+ confidence: 0,
8106
+ emotional_tone: 'Neutral',
8107
+ urgency: 'Low',
8108
+ priority: 3,
8109
+ message_preview: message_text.substring(0, 150),
8110
+ error: error.message,
8111
+ timestamp: new Date().toISOString(),
8112
+ };
8113
+ }
8114
+ };
8115
+
8116
+ // Helper functions
8117
+ function analyzeMessageCharacteristics(message, category) {
8118
+ const wordCount = message.split(/\s+/).length;
8119
+ const charCount = message.length;
8120
+ const containsQuestions = /[\?]|(can you|could you|would you|will you|do you|are you|is there|how|what|when|where|why|who)/i.test(message);
8121
+ const containsRequests = /(please|can you|could you|would you|need you|want you|help me|assist)/i.test(message);
8122
+ const containsUrgency = /(urgent|asap|immediately|right now|emergency|quick|fast|hurry)/i.test(message);
8123
+ const containsTimeReferences = /\b(today|tomorrow|now|soon|later|tonight|morning|afternoon|evening)\b/i.test(message);
8124
+ const containsEmoticons = /[:;][\-]?[\)\(DP]|<\/?3|\([^\)]*\)|[\u{1F600}-\u{1F64F}]/gu.test(message);
8125
+
8126
+ return {
8127
+ word_count: wordCount,
8128
+ char_count: charCount,
8129
+ contains_questions: containsQuestions,
8130
+ contains_requests: containsRequests,
8131
+ time_sensitive: containsTimeReferences || containsUrgency,
8132
+ has_emoticons: containsEmoticons,
8133
+ message_type: charCount < 50 ? 'Short' : charCount < 200 ? 'Medium' : 'Long',
8134
+ };
8135
+ }
8136
+
8137
+ function calculateMessagePriority(urgency, category, relationship) {
8138
+ let priority = 3; // Default medium priority
8139
+
8140
+ // Emergency categories get highest priority
8141
+ if (urgency === 'Emergency' || category.includes('Emergency')) {
8142
+ return 1;
8143
+ }
8144
+
8145
+ // High urgency
8146
+ if (urgency === 'High' || category.includes('Urgent')) {
8147
+ priority = 2;
8148
+ }
8149
+
8150
+ // Low urgency or casual messages
8151
+ if (urgency === 'Low' || category.includes('Casual') || category.includes('General Chat') || category.includes('Random Thought')) {
8152
+ priority = 4;
8153
+ }
8154
+
8155
+ // Adjust based on relationship
8156
+ if (relationship === 'Family' || relationship === 'Spouse' || relationship === 'Close Friend') {
8157
+ priority = Math.max(1, priority - 1); // Higher priority for close relations
8158
+ }
8159
+
8160
+ return Math.min(Math.max(priority, 1), 5); // Ensure 1-5 scale
8161
+ }
8162
+
8163
+ function estimateResponseTime(category, relationship) {
8164
+ const baseTimes = {
8165
+ 'Emergency Alert': 'Immediately',
8166
+ 'Urgent Assistance': 'Within minutes',
8167
+ 'Help Request': 'Within 30 minutes',
8168
+ 'Question Asking': 'Within hours',
8169
+ 'Meeting Coordination': 'Within 2 hours',
8170
+ 'Casual Conversation': 'Within 24 hours',
8171
+ 'General Chat': 'Within 48 hours',
8172
+ };
8173
+
8174
+ // Find matching base time
8175
+ for (const [key, time] of Object.entries(baseTimes)) {
8176
+ if (category.includes(key) || key.includes(category.split(' ')[0])) {
8177
+ return time;
8178
+ }
8179
+ }
8180
+
8181
+ // Default based on relationship
8182
+ switch (relationship) {
8183
+ case 'Close Friend':
8184
+ case 'Family':
8185
+ case 'Spouse':
8186
+ return 'Within 12 hours';
8187
+ case 'Colleague':
8188
+ case 'Professional':
8189
+ return 'Within business hours';
8190
+ case 'Acquaintance':
8191
+ return 'Within 2 days';
8192
+ default:
8193
+ return 'Within 24 hours';
8194
+ }
8195
+ }
8196
+
8197
+ function generateAutoReplySuggestion(category, tone) {
8198
+ const suggestions = {
8199
+ 'Meeting Coordination': "Got it! I'll be there.",
8200
+ 'Question Asking': 'Let me check and get back to you.',
8201
+ 'Urgent Assistance': 'On it! Getting help now.',
8202
+ 'Casual Conversation': 'Hey! Good to hear from you.',
8203
+ 'Thank You Message': "You're welcome! 😊",
8204
+ 'Birthday Wishes': 'Thank you so much! 🎉',
8205
+ };
8206
+
8207
+ for (const [key, reply] of Object.entries(suggestions)) {
8208
+ if (category.includes(key)) {
8209
+ return reply;
8210
+ }
8211
+ }
8212
+
8213
+ // Generic suggestions based on tone
8214
+ switch (tone) {
8215
+ case 'Positive':
8216
+ return 'Great! Thanks for sharing!';
8217
+ case 'Negative':
8218
+ return 'I understand. Let me know if I can help.';
8219
+ case 'Urgent':
8220
+ return 'Received. Looking into this now.';
8221
+ default:
8222
+ return 'Got your message. Talk soon!';
8223
+ }
8224
+ }
8225
+
8226
+ function shouldScheduleFollowUp(category, urgency) {
8227
+ const followUpCategories = ['Question Asking', 'Information Request', 'Meeting Coordination', 'Help Request', 'Task Assignment', 'Deadline Reminder'];
8228
+
8229
+ return followUpCategories.some((fc) => category.includes(fc)) && (urgency === 'Medium' || urgency === 'High');
8230
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xuda.io/ai_module",
3
- "version": "1.1.4641",
3
+ "version": "1.1.4642",
4
4
  "description": "Xuda AI Module",
5
5
  "main": "index.mjs",
6
6
  "type": "module",