@xuda.io/ai_module 1.1.4640 → 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.
- package/index.mjs +522 -43
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -7364,7 +7364,6 @@ Category:`;
|
|
|
7364
7364
|
}
|
|
7365
7365
|
};
|
|
7366
7366
|
|
|
7367
|
-
|
|
7368
7367
|
export const categorize_ai_prompt = async function (uid, prompt_text, account_profile_info) {
|
|
7369
7368
|
const ai_prompt_categories = [
|
|
7370
7369
|
// Creative & Content Generation (1-15)
|
|
@@ -7383,7 +7382,7 @@ export const categorize_ai_prompt = async function (uid, prompt_text, account_pr
|
|
|
7383
7382
|
'Resume / Cover Letter',
|
|
7384
7383
|
'Business Communication',
|
|
7385
7384
|
'Technical Documentation',
|
|
7386
|
-
|
|
7385
|
+
|
|
7387
7386
|
// Analysis & Research (16-30)
|
|
7388
7387
|
'Data Analysis Request',
|
|
7389
7388
|
'Research Assistance',
|
|
@@ -7400,7 +7399,7 @@ export const categorize_ai_prompt = async function (uid, prompt_text, account_pr
|
|
|
7400
7399
|
'Document Analysis',
|
|
7401
7400
|
'Text Summarization',
|
|
7402
7401
|
'Comparative Analysis',
|
|
7403
|
-
|
|
7402
|
+
|
|
7404
7403
|
// Technical & Programming (31-45)
|
|
7405
7404
|
'Code Generation',
|
|
7406
7405
|
'Bug Fixing',
|
|
@@ -7417,7 +7416,7 @@ export const categorize_ai_prompt = async function (uid, prompt_text, account_pr
|
|
|
7417
7416
|
'Programming Tutorial',
|
|
7418
7417
|
'Code Translation',
|
|
7419
7418
|
'Technical Support',
|
|
7420
|
-
|
|
7419
|
+
|
|
7421
7420
|
// Learning & Education (46-60)
|
|
7422
7421
|
'Concept Explanation',
|
|
7423
7422
|
'Homework Help',
|
|
@@ -7434,7 +7433,7 @@ export const categorize_ai_prompt = async function (uid, prompt_text, account_pr
|
|
|
7434
7433
|
'Course Design',
|
|
7435
7434
|
'Teaching Material',
|
|
7436
7435
|
'Knowledge Assessment',
|
|
7437
|
-
|
|
7436
|
+
|
|
7438
7437
|
// Business & Strategy (61-75)
|
|
7439
7438
|
'Business Strategy',
|
|
7440
7439
|
'Marketing Strategy',
|
|
@@ -7451,7 +7450,7 @@ export const categorize_ai_prompt = async function (uid, prompt_text, account_pr
|
|
|
7451
7450
|
'Negotiation Strategy',
|
|
7452
7451
|
'Leadership Advice',
|
|
7453
7452
|
'Management Consulting',
|
|
7454
|
-
|
|
7453
|
+
|
|
7455
7454
|
// Personal & Lifestyle (76-90)
|
|
7456
7455
|
'Personal Advice',
|
|
7457
7456
|
'Relationship Advice',
|
|
@@ -7468,7 +7467,7 @@ export const categorize_ai_prompt = async function (uid, prompt_text, account_pr
|
|
|
7468
7467
|
'Hobby Assistance',
|
|
7469
7468
|
'Recipe Creation',
|
|
7470
7469
|
'Event Planning',
|
|
7471
|
-
|
|
7470
|
+
|
|
7472
7471
|
// Analysis & Problem Solving (91-105)
|
|
7473
7472
|
'Problem Solving',
|
|
7474
7473
|
'Decision Making',
|
|
@@ -7485,7 +7484,7 @@ export const categorize_ai_prompt = async function (uid, prompt_text, account_pr
|
|
|
7485
7484
|
'Prediction Request',
|
|
7486
7485
|
'Forecasting',
|
|
7487
7486
|
'Simulation Request',
|
|
7488
|
-
|
|
7487
|
+
|
|
7489
7488
|
// Specialized Domains (106-120)
|
|
7490
7489
|
'Legal Analysis',
|
|
7491
7490
|
'Medical Information',
|
|
@@ -7502,7 +7501,7 @@ export const categorize_ai_prompt = async function (uid, prompt_text, account_pr
|
|
|
7502
7501
|
'Cybersecurity',
|
|
7503
7502
|
'Climate / Environment',
|
|
7504
7503
|
'Public Policy',
|
|
7505
|
-
|
|
7504
|
+
|
|
7506
7505
|
// Interactive & Conversational (121-130)
|
|
7507
7506
|
'Roleplaying / Simulation',
|
|
7508
7507
|
'Debate / Discussion',
|
|
@@ -7514,7 +7513,7 @@ export const categorize_ai_prompt = async function (uid, prompt_text, account_pr
|
|
|
7514
7513
|
'Trivia / Quiz',
|
|
7515
7514
|
'Joke Generation',
|
|
7516
7515
|
'Conversational Companion',
|
|
7517
|
-
|
|
7516
|
+
|
|
7518
7517
|
// Meta & System (131-140)
|
|
7519
7518
|
'Prompt Engineering',
|
|
7520
7519
|
'AI Capabilities Question',
|
|
@@ -7526,7 +7525,7 @@ export const categorize_ai_prompt = async function (uid, prompt_text, account_pr
|
|
|
7526
7525
|
'Fact Checking',
|
|
7527
7526
|
'Source Verification',
|
|
7528
7527
|
'Translation Request',
|
|
7529
|
-
|
|
7528
|
+
|
|
7530
7529
|
// Creative Arts (141-150)
|
|
7531
7530
|
'Visual Art Description',
|
|
7532
7531
|
'Art Style Analysis',
|
|
@@ -7538,7 +7537,7 @@ export const categorize_ai_prompt = async function (uid, prompt_text, account_pr
|
|
|
7538
7537
|
'Creative Critique',
|
|
7539
7538
|
'Artistic Inspiration',
|
|
7540
7539
|
'Design Feedback',
|
|
7541
|
-
|
|
7540
|
+
|
|
7542
7541
|
// Analysis & Processing (151-160)
|
|
7543
7542
|
'Sentiment Analysis',
|
|
7544
7543
|
'Text Classification',
|
|
@@ -7550,7 +7549,7 @@ export const categorize_ai_prompt = async function (uid, prompt_text, account_pr
|
|
|
7550
7549
|
'Grammar Correction',
|
|
7551
7550
|
'Style Improvement',
|
|
7552
7551
|
'Tone Adjustment',
|
|
7553
|
-
|
|
7552
|
+
|
|
7554
7553
|
// Planning & Organization (161-170)
|
|
7555
7554
|
'Schedule Planning',
|
|
7556
7555
|
'Task Management',
|
|
@@ -7562,7 +7561,7 @@ export const categorize_ai_prompt = async function (uid, prompt_text, account_pr
|
|
|
7562
7561
|
'Checklist Creation',
|
|
7563
7562
|
'Work Breakdown',
|
|
7564
7563
|
'Deadline Management',
|
|
7565
|
-
|
|
7564
|
+
|
|
7566
7565
|
// Communication & Social (171-180)
|
|
7567
7566
|
'Conflict Resolution',
|
|
7568
7567
|
'Communication Strategy',
|
|
@@ -7574,7 +7573,7 @@ export const categorize_ai_prompt = async function (uid, prompt_text, account_pr
|
|
|
7574
7573
|
'Community Management',
|
|
7575
7574
|
'Crisis Communication',
|
|
7576
7575
|
'Reputation Management',
|
|
7577
|
-
|
|
7576
|
+
|
|
7578
7577
|
// Technical Support & Operations (181-190)
|
|
7579
7578
|
'IT Support',
|
|
7580
7579
|
'System Troubleshooting',
|
|
@@ -7586,7 +7585,7 @@ export const categorize_ai_prompt = async function (uid, prompt_text, account_pr
|
|
|
7586
7585
|
'Customer Support',
|
|
7587
7586
|
'Service Desk',
|
|
7588
7587
|
'Incident Response',
|
|
7589
|
-
|
|
7588
|
+
|
|
7590
7589
|
// Data & Analytics (191-200)
|
|
7591
7590
|
'Data Visualization',
|
|
7592
7591
|
'Report Generation',
|
|
@@ -7597,15 +7596,18 @@ export const categorize_ai_prompt = async function (uid, prompt_text, account_pr
|
|
|
7597
7596
|
'User Behavior Analysis',
|
|
7598
7597
|
'Conversion Optimization',
|
|
7599
7598
|
'Analytics Setup',
|
|
7600
|
-
'Data Cleaning'
|
|
7601
|
-
]
|
|
7599
|
+
'Data Cleaning',
|
|
7600
|
+
];
|
|
7602
7601
|
|
|
7603
7602
|
const prompt = `Categorize the AI prompt into one of these exact categories:
|
|
7604
7603
|
|
|
7605
7604
|
AI Prompt: "${prompt_text.substring(0, 500)}${prompt_text.length > 500 ? '...' : ''}"
|
|
7606
7605
|
|
|
7607
7606
|
Available Categories (200 total, showing first 20 as examples):
|
|
7608
|
-
${ai_prompt_categories
|
|
7607
|
+
${ai_prompt_categories
|
|
7608
|
+
.slice(0, 20)
|
|
7609
|
+
.map((cat, index) => `${index + 1}. ${cat}`)
|
|
7610
|
+
.join('\n')}
|
|
7609
7611
|
[Full list of 200 categories available to the system]
|
|
7610
7612
|
|
|
7611
7613
|
Instructions:
|
|
@@ -7634,23 +7636,21 @@ Category:`;
|
|
|
7634
7636
|
secondary_category: z.string().optional(),
|
|
7635
7637
|
complexity_level: z.enum(['Basic', 'Intermediate', 'Advanced', 'Expert']).optional(),
|
|
7636
7638
|
}),
|
|
7637
|
-
metadata: {
|
|
7638
|
-
func: 'categorize_ai_prompt',
|
|
7639
|
+
metadata: {
|
|
7640
|
+
func: 'categorize_ai_prompt',
|
|
7639
7641
|
prompt_length: prompt_text.length,
|
|
7640
7642
|
prompt_hash: await hashPrompt(prompt_text), // Optional: hash for deduplication
|
|
7641
|
-
timestamp: new Date().toISOString()
|
|
7643
|
+
timestamp: new Date().toISOString(),
|
|
7642
7644
|
},
|
|
7643
7645
|
account_profile_info,
|
|
7644
7646
|
});
|
|
7645
7647
|
|
|
7646
7648
|
if (prompt_category_ret && prompt_category_ret.code > -1) {
|
|
7647
|
-
const data = typeof prompt_category_ret.data === 'string'
|
|
7648
|
-
|
|
7649
|
-
: prompt_category_ret.data;
|
|
7650
|
-
|
|
7649
|
+
const data = typeof prompt_category_ret.data === 'string' ? JSON.parse(prompt_category_ret.data) : prompt_category_ret.data;
|
|
7650
|
+
|
|
7651
7651
|
// Additional analysis based on category
|
|
7652
7652
|
const analysis = await analyzePromptComplexity(prompt_text, data.prompt_category);
|
|
7653
|
-
|
|
7653
|
+
|
|
7654
7654
|
return {
|
|
7655
7655
|
success: true,
|
|
7656
7656
|
category: data.prompt_category,
|
|
@@ -7662,7 +7662,7 @@ Category:`;
|
|
|
7662
7662
|
domain: getDomainFromCategory(data.prompt_category),
|
|
7663
7663
|
requires_specialized_knowledge: analysis.requires_specialized_knowledge,
|
|
7664
7664
|
prompt_preview: prompt_text.substring(0, 200),
|
|
7665
|
-
timestamp: new Date().toISOString()
|
|
7665
|
+
timestamp: new Date().toISOString(),
|
|
7666
7666
|
};
|
|
7667
7667
|
} else {
|
|
7668
7668
|
return {
|
|
@@ -7673,7 +7673,7 @@ Category:`;
|
|
|
7673
7673
|
complexity: 'Basic',
|
|
7674
7674
|
prompt_preview: prompt_text.substring(0, 200),
|
|
7675
7675
|
error: prompt_category_ret?.message || 'API call failed',
|
|
7676
|
-
timestamp: new Date().toISOString()
|
|
7676
|
+
timestamp: new Date().toISOString(),
|
|
7677
7677
|
};
|
|
7678
7678
|
}
|
|
7679
7679
|
} catch (error) {
|
|
@@ -7686,7 +7686,7 @@ Category:`;
|
|
|
7686
7686
|
complexity: 'Basic',
|
|
7687
7687
|
prompt_preview: prompt_text.substring(0, 200),
|
|
7688
7688
|
error: error.message,
|
|
7689
|
-
timestamp: new Date().toISOString()
|
|
7689
|
+
timestamp: new Date().toISOString(),
|
|
7690
7690
|
};
|
|
7691
7691
|
}
|
|
7692
7692
|
};
|
|
@@ -7698,7 +7698,7 @@ async function hashPrompt(text) {
|
|
|
7698
7698
|
const data = encoder.encode(text);
|
|
7699
7699
|
const hashBuffer = await crypto.subtle.digest('SHA-256', data);
|
|
7700
7700
|
const hashArray = Array.from(new Uint8Array(hashBuffer));
|
|
7701
|
-
return hashArray.map(b => b.toString(16).padStart(2, '0')).join('');
|
|
7701
|
+
return hashArray.map((b) => b.toString(16).padStart(2, '0')).join('');
|
|
7702
7702
|
}
|
|
7703
7703
|
|
|
7704
7704
|
async function analyzePromptComplexity(prompt, category) {
|
|
@@ -7708,10 +7708,10 @@ async function analyzePromptComplexity(prompt, category) {
|
|
|
7708
7708
|
const hasTechnicalTerms = /(\bAPI\b|\balgorithm\b|\bdebug\b|\banalysis\b)/i.test(prompt);
|
|
7709
7709
|
const hasMultipleSteps = /(first|then|next|finally|step 1|step 2)/i.test(prompt);
|
|
7710
7710
|
const requiresResearch = /(research|find|look up|investigate)/i.test(prompt);
|
|
7711
|
-
|
|
7711
|
+
|
|
7712
7712
|
let complexity = 'Basic';
|
|
7713
7713
|
let estimatedTokens = Math.ceil(wordCount * 1.3); // Rough estimation
|
|
7714
|
-
|
|
7714
|
+
|
|
7715
7715
|
if (wordCount > 100 || hasTechnicalTerms || hasMultipleSteps) {
|
|
7716
7716
|
complexity = 'Intermediate';
|
|
7717
7717
|
}
|
|
@@ -7721,31 +7721,510 @@ async function analyzePromptComplexity(prompt, category) {
|
|
|
7721
7721
|
if (wordCount > 500 || category.includes('Research') || category.includes('Analysis')) {
|
|
7722
7722
|
complexity = 'Expert';
|
|
7723
7723
|
}
|
|
7724
|
-
|
|
7724
|
+
|
|
7725
7725
|
return {
|
|
7726
7726
|
complexity,
|
|
7727
7727
|
estimated_tokens: estimatedTokens,
|
|
7728
7728
|
requires_specialized_knowledge: hasTechnicalTerms || requiresResearch,
|
|
7729
7729
|
word_count: wordCount,
|
|
7730
|
-
sentence_count: sentenceCount
|
|
7730
|
+
sentence_count: sentenceCount,
|
|
7731
7731
|
};
|
|
7732
7732
|
}
|
|
7733
7733
|
|
|
7734
7734
|
function getDomainFromCategory(category) {
|
|
7735
7735
|
// Map categories to broader domains
|
|
7736
7736
|
const domainMap = {
|
|
7737
|
-
|
|
7738
|
-
|
|
7739
|
-
|
|
7740
|
-
|
|
7741
|
-
|
|
7742
|
-
|
|
7737
|
+
Creative: /writing|story|poetry|creative|art|design/i,
|
|
7738
|
+
Technical: /code|programming|technical|software|api|database/i,
|
|
7739
|
+
Business: /business|marketing|sales|strategy|management/i,
|
|
7740
|
+
Academic: /research|study|homework|academic|education/i,
|
|
7741
|
+
Personal: /advice|personal|relationship|health|fitness/i,
|
|
7742
|
+
Analytical: /analysis|data|statistical|trend|forecast/i,
|
|
7743
7743
|
};
|
|
7744
|
-
|
|
7744
|
+
|
|
7745
7745
|
for (const [domain, pattern] of Object.entries(domainMap)) {
|
|
7746
7746
|
if (pattern.test(category)) {
|
|
7747
7747
|
return domain;
|
|
7748
7748
|
}
|
|
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
|
+
}
|