@xuda.io/ai_module 1.1.5425 → 1.1.5427

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 +69 -35
  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
  }
@@ -11186,14 +11195,44 @@ export const get_chat_suggestions = async function (req) {
11186
11195
 
11187
11196
  try {
11188
11197
  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
11198
  const conversation_item_doc = await db_module.get_app_couch_doc_native(account_profile_info.app_id, conversation_item_id);
11191
11199
  const conversation_doc = await db_module.get_app_couch_doc_native(account_profile_info.app_id, conversation_item_doc.conversation_id);
11200
+ const contentToAnalyze = (context || conversation_item_doc?.text || conversation_item_doc?.prompt || conversation_doc?.prompt || '').trim();
11192
11201
 
11193
11202
  if (conversation_item_doc.prompt_suggestions) {
11194
11203
  exclude_agents = [...new Set([...exclude_agents, ...conversation_item_doc.prompt_suggestions.map((agent) => agent.agent_id)])];
11195
11204
  }
11196
11205
 
11206
+ const is_generic_content = function (content) {
11207
+ if (!content) {
11208
+ return true;
11209
+ }
11210
+
11211
+ const normalized = content.toLowerCase().replace(/\s+/g, ' ').trim();
11212
+
11213
+ if (normalized.length < 24 && !/[{}[\]<>`]/.test(normalized)) {
11214
+ return true;
11215
+ }
11216
+
11217
+ if (/^(hi|hello|hey|good morning|good afternoon|good evening)\b/.test(normalized) && normalized.length < 140) {
11218
+ return true;
11219
+ }
11220
+
11221
+ if (/how can i help you today\??/.test(normalized)) {
11222
+ return true;
11223
+ }
11224
+
11225
+ if (/^(thanks|thank you|ok|okay|sure|sounds good|great|nice|welcome)\b/.test(normalized) && normalized.length < 80) {
11226
+ return true;
11227
+ }
11228
+
11229
+ return false;
11230
+ };
11231
+
11232
+ if (is_generic_content(contentToAnalyze)) {
11233
+ return { code: 44, data: [] };
11234
+ }
11235
+
11197
11236
  const get_agents = async function () {
11198
11237
  if (typeof ai_agents === 'undefined') {
11199
11238
  // no agents
@@ -11208,54 +11247,47 @@ export const get_chat_suggestions = async function (req) {
11208
11247
  }
11209
11248
  }
11210
11249
 
11211
- const list = [];
11212
-
11213
- for (const agent_id of ai_agents) {
11214
- try {
11215
- let ai_agent_doc;
11250
+ const agent_docs = await Promise.all(
11251
+ ai_agents.map(async (agent_id) => {
11216
11252
  try {
11217
- ai_agent_doc = await db_module.get_app_couch_doc_native(account_profile_info.app_id, agent_id);
11253
+ if (agent_id === conversation_item_doc.ai_agent_id) return null;
11254
+ if (exclude_agents.includes(agent_id)) return null;
11255
+
11256
+ let ai_agent_doc = await db_module.get_app_couch_doc_native(account_profile_info.app_id, agent_id);
11218
11257
  if (ai_agent_doc.studio_meta.shared_from_uid) {
11219
11258
  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);
11259
+ await get_account_default_project_id(ai_agent_doc.studio_meta.shared_from_uid);
11221
11260
  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
11261
  ai_agent_doc.reference_doc = reference_doc;
11223
11262
  } else if (ai_agent_doc.studio_meta.installed_from_app_uid) {
11224
11263
  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);
11264
+ await get_account_default_project_id(ai_agent_doc.studio_meta.installed_from_app_uid);
11226
11265
  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
11266
  ai_agent_doc.reference_doc = reference_doc;
11228
11267
  }
11229
11268
 
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 || [])) {
11269
+ for (const [, val] of Object.entries(ai_agent_doc?.agentConfig?.agent_tools || [])) {
11235
11270
  if (['web_search', 'table', 'file_search'].includes(val.type)) {
11236
- skip = true;
11237
- break;
11271
+ return null;
11238
11272
  }
11239
11273
  }
11240
- if (skip) continue;
11241
11274
 
11242
- list.push({
11275
+ return {
11243
11276
  agent_id,
11244
11277
  agent_name: ai_agent_doc.properties.menuName,
11245
11278
  agent_category: ai_agent_doc.studio_meta.agent_category,
11246
11279
  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
- });
11280
+ agent_instructions: ai_agent_doc?.agentConfig?.agent_instructions?.slice(0, 300),
11281
+ agent_user_guide: ai_agent_doc?.agentConfig?.agent_user_guide?.slice(0, 200),
11282
+ };
11250
11283
  } catch (err) {
11251
- throw new Error(err.message);
11284
+ console.error(err.message);
11285
+ return null;
11252
11286
  }
11253
- } catch (err) {
11254
- console.error(err.message);
11255
- }
11256
- }
11287
+ }),
11288
+ );
11257
11289
 
11258
- return list;
11290
+ return agent_docs.filter(Boolean);
11259
11291
  };
11260
11292
 
11261
11293
  const get_suggestions = async function () {
@@ -11281,22 +11313,24 @@ export const get_chat_suggestions = async function (req) {
11281
11313
  1. Return fewer than ${no_of_suggestions} agents when only a few are relevant.
11282
11314
  2. Return an empty array when none of the agents are a strong match.
11283
11315
  3. Do not fill the list just to reach ${no_of_suggestions}.
11284
- 4. Only include an agent when its relevance_score is 70 or higher.
11316
+ 4. Only include an agent when its relevance_score is 85 or higher.
11285
11317
  5. Never invent agent ids. Use only ids from the ## Agent Source.
11286
11318
  6. Never return any agent whose id appears in ## Excluded Agent IDs.
11319
+ 7. Base every suggestion on explicit evidence in ## Content To Analyze, not on assumptions about what might be useful later.
11320
+ 8. If ## Content To Analyze is only a greeting, acknowledgement, chit-chat, or other generic text with no concrete task, return [].
11321
+ 9. Do not use the user profile by itself as a reason to recommend technical, coding, HTML, or app-building agents.
11287
11322
 
11288
11323
  Selection Strategy:
11289
- 1. Format Compatibility: Analyze the ## ${type} to Process. If it contains structured JSON, component definitions, or raw HTML, prioritize agents capable of transforming these formats (e.g., converting HTML/JSON to functional apps).
11290
- 2. Workflow Continuity: Focus on the "Lifecycle" of the project. If a UI or content has been drafted, the logical next step is conversion to a production-ready format, styling, or deployment.
11291
- 3. Contextual Relevance: Match the user's business profile and prompt category only when they materially improve the fit.
11324
+ 1. Evidence First: Recommend an agent only when the content clearly mentions a task, artifact, or format that the agent directly handles.
11325
+ 2. Format Compatibility: If the content explicitly contains structured JSON, component definitions, code, markup, or a direct request for those formats, prioritize agents specialized for that exact format.
11326
+ 3. Workflow Continuity: Use next-step reasoning only when the current content already demonstrates a concrete project step.
11292
11327
  4. Reject generic or weakly related agents. If the match is ambiguous, leave the agent out.
11293
11328
 
11294
11329
 
11295
- ## ${type}: ${context ? context : 'Use the previous response output as the content to analyze for next agents.'}
11330
+ ## Content To Analyze (${type}): ${contentToAnalyze || 'No usable content.'}
11296
11331
 
11297
11332
  Input Context:
11298
11333
 
11299
- User Profile: ${JSON.stringify(account_doc.account_info)}
11300
11334
  Prompt Category: ${conversation_doc?.category_info?.category}
11301
11335
  Excluded Agent IDs: ${JSON.stringify(exclude_agents)}
11302
11336
 
@@ -11343,7 +11377,7 @@ export const get_chat_suggestions = async function (req) {
11343
11377
  if (seen.has(agent.agent_id)) {
11344
11378
  return false;
11345
11379
  }
11346
- if (typeof agent.relevance_score !== 'number' || agent.relevance_score < 70) {
11380
+ if (typeof agent.relevance_score !== 'number' || agent.relevance_score < 85) {
11347
11381
  return false;
11348
11382
  }
11349
11383
  const short_action = agent.short_action?.trim();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xuda.io/ai_module",
3
- "version": "1.1.5425",
3
+ "version": "1.1.5427",
4
4
  "description": "Xuda AI Module",
5
5
  "main": "index.mjs",
6
6
  "type": "module",