@xuda.io/ai_module 1.1.5127 → 1.1.5129

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 +42 -34
  2. package/package.json +1 -1
package/index.mjs CHANGED
@@ -4785,7 +4785,7 @@ setTimeout(async () => {
4785
4785
 
4786
4786
  // await init_studio_units();
4787
4787
  let ret;
4788
- ret = await get_chat_suggestions(uid, [], 'coi_7b65b783af38b91c8ec4c499d3694bab');
4788
+ // ret = await get_chat_suggestions(uid, [], 'coi_7b65b783af38b91c8ec4c499d3694bab');
4789
4789
  // ret = await get_active_account_profile_info(uid);
4790
4790
  // ret = await is_spam_email(uid, 'dsgr8-2994400420@gigs.craigslist.org', 'To: You, From: Us - 70% Off Stickers & Labels Today Only');
4791
4791
  // ret = await is_spam_email(uid, 'noreply@tm.openai.com', 'Please update your Plus payment method', account_profile_info);
@@ -10836,8 +10836,6 @@ export const open_ai_alive_check = async function () {};
10836
10836
  // };
10837
10837
 
10838
10838
  export const get_chat_suggestions = async function (uid, ai_agents, conversation_item_id, ai_model = _conf.default_ai_model) {
10839
- let ret = [];
10840
-
10841
10839
  try {
10842
10840
  const account_profile_info = await get_active_account_profile_info(uid);
10843
10841
  const account_doc = await db_module.get_couch_doc_native('xuda_accounts', uid);
@@ -10852,6 +10850,7 @@ export const get_chat_suggestions = async function (uid, ai_agents, conversation
10852
10850
  // auto agent mode
10853
10851
  const ai_agents_ret = await get_user_ai_agents(uid);
10854
10852
  for (const doc of ai_agents_ret.docs) {
10853
+ if (doc._id === conversation_item_doc.ai_agent_id) continue; //exclude the current agent from list
10855
10854
  ai_agents.push(doc._id);
10856
10855
  }
10857
10856
  }
@@ -10886,50 +10885,59 @@ export const get_chat_suggestions = async function (uid, ai_agents, conversation
10886
10885
  return list;
10887
10886
  };
10888
10887
 
10889
- const agents_docs = await get_agents();
10890
-
10891
- const AgentItemSchema = z.object({
10892
- agent_id: z.string().describe('The unique identifier for the agent'),
10893
- short_action: z.string().describe('A brief, 2-4 word call to action'),
10894
- agent_description: z.string().describe("A professional description of the agent's capabilities"),
10895
- });
10888
+ const get_suggestions = async function () {
10889
+ const AgentItemSchema = z.object({
10890
+ agent_id: z.string().describe('The unique identifier for the agent'),
10891
+ short_action: z.string().describe('A brief, 2-4 word call to action'),
10892
+ agent_description: z.string().describe("A professional description of the agent's capabilities"),
10893
+ });
10896
10894
 
10897
- // Define the response format as a fixed-length array of 5
10898
- const AgentResponseSchema = z.object({
10899
- agents: z.array(AgentItemSchema).length(5),
10900
- });
10895
+ // Define the response format as a fixed-length array of 5
10896
+ const AgentResponseSchema = z.object({
10897
+ agents: z.array(AgentItemSchema).length(5),
10898
+ });
10901
10899
 
10902
- const chat_ret = await submit_chat_gpt_prompt({
10903
- uid,
10904
- prompt: `
10900
+ const chat_ret = await submit_chat_gpt_prompt({
10901
+ uid,
10902
+ prompt: `
10905
10903
 
10906
- Role: You are a routing assistant.
10904
+ Role: You are a routing assistant.
10907
10905
 
10908
- Task: Analyze the provided user context and select the 5 most relevant agents from the ## Agent List.
10906
+ Task: Analyze the provided user context and select the 5 most relevant agents from the ## Agent List.
10909
10907
 
10910
- Selection Logic:
10911
- Base your selection on the alignment between the agent's purpose and the following context:
10908
+ Selection Logic:
10909
+ Base your selection on the alignment between the agent's purpose and the following context:
10912
10910
 
10913
- User Profile: ${JSON.stringify(account_doc.account_info)}
10911
+ User Profile: ${JSON.stringify(account_doc.account_info)}
10914
10912
 
10915
- Recent Interaction: The user asked ${conversation_item_doc.prompt || conversation_doc.prompt}, categorized as ${conversation_doc?.category_info?.category}, which resulted in the response: ${conversation_item_doc.text}.
10913
+ Recent Interaction: The user asked ${conversation_item_doc.prompt || conversation_doc.prompt}, categorized as ${conversation_doc?.category_info?.category}, which resulted in the response: ${conversation_item_doc.text}.
10916
10914
 
10917
- Data Source: > ${JSON.stringify(agents_docs)}
10915
+ Data Source: > ${JSON.stringify(agents_docs)}
10918
10916
 
10919
- Output: > Return a JSON array of exactly 5 objects following this schema:
10920
- [{ "agent_id": "string", "short_action": "string", "agent_description": "string" }]
10917
+ Output: > Return a JSON array of exactly 5 objects following this schema:
10918
+ [{ "agent_id": "string", "short_action": "string", "agent_description": "string" }]
10921
10919
 
10922
- ## output example:
10923
- [{agent_id:"392_agn_55cb328d2743",short_action:"Create article","agent_description":"create proffessional article..."}]
10920
+ ## output example:
10921
+ [{agent_id:"392_agn_55cb328d2743",short_action:"Create article","agent_description":"create proffessional article..."}]
10924
10922
 
10925
10923
  `,
10926
- model: ai_model,
10927
- response_format: AgentResponseSchema,
10928
- metadata: { conversation_item_id, func: 'get_chat_suggestions' },
10929
- account_profile_info,
10930
- });
10924
+ model: ai_model,
10925
+ response_format: AgentResponseSchema,
10926
+ metadata: { conversation_item_id, func: 'get_chat_suggestions' },
10927
+ account_profile_info,
10928
+ });
10929
+ try {
10930
+ const ret = JSON5.parse(chat_ret.data);
10931
+ return ret.agents;
10932
+ } catch (error) {
10933
+ return [];
10934
+ }
10935
+ };
10931
10936
 
10932
- debugger;
10937
+ const agents_docs = await get_agents();
10938
+ const suggestions = await get_suggestions();
10939
+
10940
+ return { code: 44, data: suggestions };
10933
10941
  } catch (err) {
10934
10942
  return { code: -44, data: err.message || String(err) };
10935
10943
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xuda.io/ai_module",
3
- "version": "1.1.5127",
3
+ "version": "1.1.5129",
4
4
  "description": "Xuda AI Module",
5
5
  "main": "index.mjs",
6
6
  "type": "module",