@xuda.io/ai_module 1.1.5426 → 1.1.5428

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 +61 -30
  2. package/package.json +1 -1
package/index.mjs CHANGED
@@ -4212,6 +4212,16 @@ const ai_chat_conversation = async function (req, job_id, headers) {
4212
4212
 
4213
4213
  const render_output_suggestions = async function (response_conversation_item_id) {
4214
4214
  console.log('prompt_suggestions', prompt_suggestions);
4215
+ let in_conversation_item_doc = await db_module.get_app_couch_doc_native(account_profile_info.app_id, response_conversation_item_id);
4216
+ const response_text = (in_conversation_item_doc?.text || in_conversation_item_doc?.prompt || '').toLowerCase().trim();
4217
+
4218
+ if (!response_text || /how can i help you today\??/.test(response_text) || (/^(hi|hello|hey)\b/.test(response_text) && response_text.length < 140)) {
4219
+ in_conversation_item_doc.output_suggestions = [];
4220
+ await db_module.save_app_couch_doc_native(account_profile_info.app_id, in_conversation_item_doc);
4221
+ emitToDashboard('suggestions', JSON.stringify([]));
4222
+ return { code: 44, data: [] };
4223
+ }
4224
+
4215
4225
  const exclude_agents = prompt_suggestions.map((agent) => agent.agent_id);
4216
4226
  const ret = await get_chat_suggestions({ uid, type: 'chat response', ai_agents, conversation_item_id: response_conversation_item_id, exclude_agents });
4217
4227
 
@@ -4220,7 +4230,6 @@ const ai_chat_conversation = async function (req, job_id, headers) {
4220
4230
  emitToDashboard('suggestions', JSON.stringify(ret.data));
4221
4231
  // emitToDashboard('stream_end');
4222
4232
 
4223
- let in_conversation_item_doc = await db_module.get_app_couch_doc_native(account_profile_info.app_id, response_conversation_item_id);
4224
4233
  in_conversation_item_doc.output_suggestions = ret.data || [];
4225
4234
  const save_ret = await db_module.save_app_couch_doc_native(account_profile_info.app_id, in_conversation_item_doc);
4226
4235
  }
@@ -4838,6 +4847,7 @@ const ai_chat_conversation = async function (req, job_id, headers) {
4838
4847
  }
4839
4848
 
4840
4849
  if (prompt_suggestions.length) {
4850
+ debugger;
4841
4851
  prompt_selected_suggestion = await render_prompt_suggestions();
4842
4852
 
4843
4853
  if (prompt_selected_suggestion) {
@@ -11186,14 +11196,44 @@ export const get_chat_suggestions = async function (req) {
11186
11196
 
11187
11197
  try {
11188
11198
  const account_profile_info = await get_active_account_profile_info(uid);
11189
- const account_doc = await db_module.get_couch_doc_native('xuda_accounts', uid);
11190
11199
  const conversation_item_doc = await db_module.get_app_couch_doc_native(account_profile_info.app_id, conversation_item_id);
11191
11200
  const conversation_doc = await db_module.get_app_couch_doc_native(account_profile_info.app_id, conversation_item_doc.conversation_id);
11201
+ const contentToAnalyze = (context || conversation_item_doc?.text || conversation_item_doc?.prompt || conversation_doc?.prompt || '').trim();
11192
11202
 
11193
11203
  if (conversation_item_doc.prompt_suggestions) {
11194
11204
  exclude_agents = [...new Set([...exclude_agents, ...conversation_item_doc.prompt_suggestions.map((agent) => agent.agent_id)])];
11195
11205
  }
11196
11206
 
11207
+ const is_generic_content = function (content) {
11208
+ if (!content) {
11209
+ return true;
11210
+ }
11211
+
11212
+ const normalized = content.toLowerCase().replace(/\s+/g, ' ').trim();
11213
+
11214
+ if (normalized.length < 24 && !/[{}[\]<>`]/.test(normalized)) {
11215
+ return true;
11216
+ }
11217
+
11218
+ if (/^(hi|hello|hey|good morning|good afternoon|good evening)\b/.test(normalized) && normalized.length < 140) {
11219
+ return true;
11220
+ }
11221
+
11222
+ if (/how can i help you today\??/.test(normalized)) {
11223
+ return true;
11224
+ }
11225
+
11226
+ if (/^(thanks|thank you|ok|okay|sure|sounds good|great|nice|welcome)\b/.test(normalized) && normalized.length < 80) {
11227
+ return true;
11228
+ }
11229
+
11230
+ return false;
11231
+ };
11232
+
11233
+ if (is_generic_content(contentToAnalyze)) {
11234
+ return { code: 44, data: [] };
11235
+ }
11236
+
11197
11237
  const get_agents = async function () {
11198
11238
  if (typeof ai_agents === 'undefined') {
11199
11239
  // no agents
@@ -11208,59 +11248,51 @@ export const get_chat_suggestions = async function (req) {
11208
11248
  }
11209
11249
  }
11210
11250
 
11211
- const list = [];
11212
-
11213
- for (const agent_id of ai_agents) {
11214
- try {
11215
- let ai_agent_doc;
11251
+ const agent_docs = await Promise.all(
11252
+ ai_agents.map(async (agent_id) => {
11216
11253
  try {
11217
- ai_agent_doc = await db_module.get_app_couch_doc_native(account_profile_info.app_id, agent_id);
11254
+ if (agent_id === conversation_item_doc.ai_agent_id) return null;
11255
+ if (exclude_agents.includes(agent_id)) return null;
11256
+
11257
+ let ai_agent_doc = await db_module.get_app_couch_doc_native(account_profile_info.app_id, agent_id);
11218
11258
  if (ai_agent_doc.studio_meta.shared_from_uid) {
11219
11259
  const reference_doc = _.cloneDeep(ai_agent_doc);
11220
- const app_id = await get_account_default_project_id(ai_agent_doc.studio_meta.shared_from_uid);
11260
+ await get_account_default_project_id(ai_agent_doc.studio_meta.shared_from_uid);
11221
11261
  ai_agent_doc = await db_module.get_app_couch_doc_native(account_profile_info.app_id, ai_agent_doc.studio_meta.share_item_id);
11222
11262
  ai_agent_doc.reference_doc = reference_doc;
11223
11263
  } else if (ai_agent_doc.studio_meta.installed_from_app_uid) {
11224
11264
  const reference_doc = _.cloneDeep(ai_agent_doc);
11225
- const app_id = await get_account_default_project_id(ai_agent_doc.studio_meta.installed_from_app_uid);
11265
+ await get_account_default_project_id(ai_agent_doc.studio_meta.installed_from_app_uid);
11226
11266
  ai_agent_doc = await db_module.get_app_couch_doc_native(account_profile_info.app_id, ai_agent_doc.studio_meta.share_item_id);
11227
11267
  ai_agent_doc.reference_doc = reference_doc;
11228
11268
  }
11229
11269
 
11230
- if (agent_id === conversation_item_doc.ai_agent_id) continue; //exclude the current agent from list
11231
- if (exclude_agents.includes(agent_id)) continue;
11232
-
11233
- let skip = false;
11234
- for (const [key, val] of Object.entries(ai_agent_doc?.agentConfig?.agent_tools || [])) {
11270
+ for (const [, val] of Object.entries(ai_agent_doc?.agentConfig?.agent_tools || [])) {
11235
11271
  if (['web_search', 'table', 'file_search'].includes(val.type)) {
11236
- skip = true;
11237
- break;
11272
+ return null;
11238
11273
  }
11239
11274
  }
11240
- if (skip) continue;
11241
11275
 
11242
- list.push({
11276
+ return {
11243
11277
  agent_id,
11244
11278
  agent_name: ai_agent_doc.properties.menuName,
11245
11279
  agent_category: ai_agent_doc.studio_meta.agent_category,
11246
11280
  agent_industry: ai_agent_doc.studio_meta.agent_industry,
11247
- agent_instructions: ai_agent_doc?.agentConfig?.agent_instructions,
11248
- agent_user_guide: ai_agent_doc?.agentConfig?.agent_user_guide,
11249
- });
11281
+ agent_instructions: ai_agent_doc?.agentConfig?.agent_instructions?.slice(0, 300),
11282
+ agent_user_guide: ai_agent_doc?.agentConfig?.agent_user_guide?.slice(0, 200),
11283
+ };
11250
11284
  } catch (err) {
11251
- throw new Error(err.message);
11285
+ console.error(err.message);
11286
+ return null;
11252
11287
  }
11253
- } catch (err) {
11254
- console.error(err.message);
11255
- }
11256
- }
11288
+ }),
11289
+ );
11257
11290
 
11258
- return list;
11291
+ return agent_docs.filter(Boolean);
11259
11292
  };
11260
11293
 
11261
11294
  const get_suggestions = async function () {
11262
11295
  const availableAgentIds = new Set(agents_docs.map((agent) => agent.agent_id));
11263
- const contentToAnalyze = context || conversation_item_doc?.text || conversation_item_doc?.prompt || conversation_doc?.prompt || '';
11264
11296
  const AgentItemSchema = z.object({
11265
11297
  type: z.literal('agent').describe('Constant identifier, always "agent"'),
11266
11298
  agent_id: z.string().describe('The unique identifier for the agent'),
@@ -11300,7 +11332,6 @@ export const get_chat_suggestions = async function (req) {
11300
11332
 
11301
11333
  Input Context:
11302
11334
 
11303
- User Profile: ${JSON.stringify(account_doc.account_info)}
11304
11335
  Prompt Category: ${conversation_doc?.category_info?.category}
11305
11336
  Excluded Agent IDs: ${JSON.stringify(exclude_agents)}
11306
11337
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xuda.io/ai_module",
3
- "version": "1.1.5426",
3
+ "version": "1.1.5428",
4
4
  "description": "Xuda AI Module",
5
5
  "main": "index.mjs",
6
6
  "type": "module",