@xuda.io/ai_module 1.1.5426 → 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.
- package/index.mjs +60 -30
- 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,59 +11247,51 @@ export const get_chat_suggestions = async function (req) {
|
|
|
11208
11247
|
}
|
|
11209
11248
|
}
|
|
11210
11249
|
|
|
11211
|
-
const
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
11237
|
-
break;
|
|
11271
|
+
return null;
|
|
11238
11272
|
}
|
|
11239
11273
|
}
|
|
11240
|
-
if (skip) continue;
|
|
11241
11274
|
|
|
11242
|
-
|
|
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
|
-
|
|
11284
|
+
console.error(err.message);
|
|
11285
|
+
return null;
|
|
11252
11286
|
}
|
|
11253
|
-
}
|
|
11254
|
-
|
|
11255
|
-
}
|
|
11256
|
-
}
|
|
11287
|
+
}),
|
|
11288
|
+
);
|
|
11257
11289
|
|
|
11258
|
-
return
|
|
11290
|
+
return agent_docs.filter(Boolean);
|
|
11259
11291
|
};
|
|
11260
11292
|
|
|
11261
11293
|
const get_suggestions = async function () {
|
|
11262
11294
|
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
11295
|
const AgentItemSchema = z.object({
|
|
11265
11296
|
type: z.literal('agent').describe('Constant identifier, always "agent"'),
|
|
11266
11297
|
agent_id: z.string().describe('The unique identifier for the agent'),
|
|
@@ -11300,7 +11331,6 @@ export const get_chat_suggestions = async function (req) {
|
|
|
11300
11331
|
|
|
11301
11332
|
Input Context:
|
|
11302
11333
|
|
|
11303
|
-
User Profile: ${JSON.stringify(account_doc.account_info)}
|
|
11304
11334
|
Prompt Category: ${conversation_doc?.category_info?.category}
|
|
11305
11335
|
Excluded Agent IDs: ${JSON.stringify(exclude_agents)}
|
|
11306
11336
|
|