@xuda.io/ai_module 1.1.4634 → 1.1.4636

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 +105 -27
  2. package/package.json +1 -1
package/index.mjs CHANGED
@@ -7163,36 +7163,114 @@ export const get_name_from_email_addr = async function (uid, email, account_prof
7163
7163
  };
7164
7164
 
7165
7165
  export const categorize_email_subject = async function (uid, subject, account_profile_info) {
7166
- const email_categories = [];
7167
- const categoryNames = categories.map((c) => c.name);
7168
- const allSubCategories = categories.flatMap((c) => c.sub);
7169
-
7170
- const email_category_ret = await submit_chat_gpt_prompt({
7171
- uid,
7172
- prompt: `categorize the email subject: "${subject}".
7173
- `,
7174
- model: 'gpt-5-nano',
7175
- response_format: z.object({
7176
- email_category: z.enum(email_categories),
7177
- }),
7178
- metadata: { func: 'categorize_email_subject' },
7179
- account_profile_info,
7180
- });
7166
+ // Define comprehensive email categories
7167
+ const email_categories = [
7168
+ 'Meeting Invitations',
7169
+ 'Meeting Updates / Cancellations',
7170
+ 'Team Announcements',
7171
+ 'One-on-One Requests',
7172
+ 'Project Collaboration',
7173
+ 'Job Applications',
7174
+ 'Interview Scheduling',
7175
+ 'Contract / Agreement',
7176
+ 'Invoice / Billing',
7177
+ 'Business Proposal',
7178
+ 'Client Inquiry',
7179
+ 'Sales / Promotional',
7180
+ 'Partnership Opportunity',
7181
+ 'Report / Analysis',
7182
+ 'Performance Review',
7183
+ 'Payment Received',
7184
+ 'Payment Request / Reminder',
7185
+ 'Subscription Renewal',
7186
+ 'Order Confirmation',
7187
+ 'Shipping Notification',
7188
+ 'Refund / Return',
7189
+ 'Account Verification',
7190
+ 'Password Reset',
7191
+ 'Security Alert',
7192
+ 'Privacy Policy Update',
7193
+ 'Terms of Service Change',
7194
+ 'Event Invitation (Social)',
7195
+ 'Connection Request',
7196
+ 'Newsletter',
7197
+ 'Blog / Content Update',
7198
+ 'Survey / Feedback Request',
7199
+ 'System Maintenance',
7200
+ 'Software Update',
7201
+ 'Service Outage',
7202
+ 'New Feature Announcement',
7203
+ 'Course Enrollment',
7204
+ 'Webinar Invitation',
7205
+ 'Certification / Training',
7206
+ 'Research / Study Invitation',
7207
+ 'Appointment Reminder',
7208
+ 'Health Tips / Newsletter',
7209
+ 'Prescription Ready',
7210
+ 'Travel Booking Confirmation',
7211
+ 'Flight / Hotel Updates',
7212
+ 'Event Tickets',
7213
+ 'Notification / Alert',
7214
+ 'Confirmation (General)',
7215
+ 'Welcome / Onboarding',
7216
+ 'Follow-up / Reminder',
7217
+ 'Miscellaneous / Unclassified'
7218
+ ] as const;
7219
+
7220
+ // Create a more detailed prompt with context
7221
+ const prompt = `Categorize the email subject into one of these exact categories:
7222
+
7223
+ Email Subject: "${subject}"
7224
+
7225
+ Available Categories:
7226
+ ${email_categories.map((cat, index) => `${index + 1}. ${cat}`).join('\n')}
7227
+
7228
+ Instructions:
7229
+ 1. Choose the single most relevant category
7230
+ 2. Return only the exact category name as it appears above
7231
+ 3. If unsure, choose "Miscellaneous / Unclassified"
7232
+
7233
+ Category:`;
7181
7234
 
7182
7235
  try {
7183
- if (business_info_ret.code > -1) {
7184
- const data = typeof business_info_ret.data === 'string' ? JSON.parse(business_info_ret.data) : business_info_ret.data;
7185
-
7186
- // Standardize country to uppercase
7187
- if (data.business_country) data.business_country = data.business_country.toUpperCase();
7188
-
7189
- // Logic to attach the ID for your database
7190
- const matched = categories.find((c) => c.name === data.business_category);
7191
- data.business_category_id = matched ? matched.id : null;
7236
+ const email_category_ret = await submit_chat_gpt_prompt({
7237
+ uid,
7238
+ prompt: prompt,
7239
+ model: 'gpt-4o-mini', // Updated to a valid model name (gpt-5-nano doesn't exist)
7240
+ response_format: z.object({
7241
+ email_category: z.enum(email_categories),
7242
+ }),
7243
+ metadata: { func: 'categorize_email_subject', subject: subject.substring(0, 100) }, // Add subject for tracking
7244
+ account_profile_info,
7245
+ });
7192
7246
 
7193
- return data;
7247
+ if (email_category_ret && email_category_ret.code > -1) {
7248
+ // Parse the response data
7249
+ const data = typeof email_category_ret.data === 'string'
7250
+ ? JSON.parse(email_category_ret.data)
7251
+ : email_category_ret.data; // Fixed variable name (was business_info_ret.data)
7252
+
7253
+ return {
7254
+ success: true,
7255
+ category: data.email_category,
7256
+ subject: subject
7257
+ };
7258
+ } else {
7259
+ console.warn('Failed to categorize email subject:', email_category_ret?.message);
7260
+ return {
7261
+ success: false,
7262
+ category: 'Miscellaneous / Unclassified',
7263
+ subject: subject,
7264
+ error: email_category_ret?.message || 'Unknown error'
7265
+ };
7194
7266
  }
7195
7267
  } catch (error) {
7196
- console.error('Error in get_business_info:', error);
7268
+ console.error('Error in categorize_email_subject:', error);
7269
+ return {
7270
+ success: false,
7271
+ category: 'Miscellaneous / Unclassified',
7272
+ subject: subject,
7273
+ error: error.message
7274
+ };
7197
7275
  }
7198
- };
7276
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xuda.io/ai_module",
3
- "version": "1.1.4634",
3
+ "version": "1.1.4636",
4
4
  "description": "Xuda AI Module",
5
5
  "main": "index.mjs",
6
6
  "type": "module",