@xuda.io/ai_module 1.1.3971 → 1.1.3973
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 +344 -342
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -4587,9 +4587,9 @@ const ai_chat_conversation = async function (req, job_id, headers) {
|
|
|
4587
4587
|
ai_agents = [];
|
|
4588
4588
|
} else if (!ai_agents.length) {
|
|
4589
4589
|
// auto agent mode
|
|
4590
|
-
const ai_agents_ret = await
|
|
4591
|
-
for (const doc of ai_agents_ret.
|
|
4592
|
-
ai_agents.push(doc.
|
|
4590
|
+
const ai_agents_ret = await get_user_ai_agents(uid);
|
|
4591
|
+
for (const doc of ai_agents_ret.docs) {
|
|
4592
|
+
ai_agents.push(doc._id);
|
|
4593
4593
|
}
|
|
4594
4594
|
}
|
|
4595
4595
|
|
|
@@ -4602,393 +4602,395 @@ const ai_chat_conversation = async function (req, job_id, headers) {
|
|
|
4602
4602
|
}
|
|
4603
4603
|
|
|
4604
4604
|
for (const agent_id of ai_agents) {
|
|
4605
|
-
let ai_agent_doc;
|
|
4606
4605
|
try {
|
|
4607
|
-
ai_agent_doc
|
|
4608
|
-
|
|
4609
|
-
|
|
4610
|
-
|
|
4611
|
-
|
|
4612
|
-
|
|
4613
|
-
|
|
4614
|
-
|
|
4615
|
-
|
|
4616
|
-
|
|
4617
|
-
|
|
4606
|
+
let ai_agent_doc;
|
|
4607
|
+
try {
|
|
4608
|
+
ai_agent_doc = await db_module.get_app_couch_doc_native(app_id, agent_id);
|
|
4609
|
+
if (ai_agent_doc.studio_meta.shared_from_uid) {
|
|
4610
|
+
const reference_doc = _.cloneDeep(ai_agent_doc);
|
|
4611
|
+
const app_id = await account_module.get_account_default_project_id(ai_agent_doc.studio_meta.shared_from_uid);
|
|
4612
|
+
ai_agent_doc = await db_module.get_app_couch_doc_native(app_id, ai_agent_doc.studio_meta.share_item_id);
|
|
4613
|
+
ai_agent_doc.reference_doc = reference_doc;
|
|
4614
|
+
} else if (ai_agent_doc.studio_meta.installed_from_uid) {
|
|
4615
|
+
const reference_doc = _.cloneDeep(ai_agent_doc);
|
|
4616
|
+
const app_id = await account_module.get_account_default_project_id(ai_agent_doc.studio_meta.installed_from_uid);
|
|
4617
|
+
ai_agent_doc = await db_module.get_app_couch_doc_native(app_id, ai_agent_doc.studio_meta.share_item_id);
|
|
4618
|
+
ai_agent_doc.reference_doc = reference_doc;
|
|
4619
|
+
}
|
|
4620
|
+
} catch (err) {
|
|
4621
|
+
throw new Error(err.message);
|
|
4618
4622
|
}
|
|
4619
|
-
} catch (err) {
|
|
4620
|
-
throw new Error(err.message);
|
|
4621
|
-
}
|
|
4622
4623
|
|
|
4623
|
-
|
|
4624
|
-
|
|
4625
|
-
|
|
4624
|
+
if (ai_agent_doc.use_tools_only) {
|
|
4625
|
+
modelSettings.toolChoice = 'required';
|
|
4626
|
+
}
|
|
4626
4627
|
|
|
4627
|
-
|
|
4628
|
-
|
|
4628
|
+
let tools = [];
|
|
4629
|
+
let tool_resources = {};
|
|
4629
4630
|
|
|
4630
|
-
|
|
4631
|
-
|
|
4632
|
-
|
|
4633
|
-
|
|
4634
|
-
|
|
4635
|
-
|
|
4636
|
-
|
|
4637
|
-
|
|
4631
|
+
for (const [key, val] of Object.entries(ai_agent_doc?.agentConfig?.agent_tools || [])) {
|
|
4632
|
+
const { name, description } = val;
|
|
4633
|
+
switch (val.type) {
|
|
4634
|
+
case 'web_search': {
|
|
4635
|
+
//hosted_web_search
|
|
4636
|
+
tools.push(webSearchTool());
|
|
4637
|
+
break;
|
|
4638
|
+
}
|
|
4638
4639
|
|
|
4639
|
-
|
|
4640
|
-
|
|
4641
|
-
|
|
4642
|
-
|
|
4643
|
-
|
|
4644
|
-
|
|
4645
|
-
|
|
4646
|
-
|
|
4647
|
-
|
|
4648
|
-
|
|
4649
|
-
|
|
4650
|
-
|
|
4651
|
-
|
|
4652
|
-
|
|
4653
|
-
|
|
4640
|
+
case 'mcp': {
|
|
4641
|
+
tools.push(
|
|
4642
|
+
hostedMcpTool({
|
|
4643
|
+
serverLabel: 'mcp_' + (val?.name?.replaceAll(' ', '_') || key), //ai_agent_doc.properties.menuName,
|
|
4644
|
+
serverUrl: val.url,
|
|
4645
|
+
headers: {
|
|
4646
|
+
Authorization: `Bearer ${val.authentication_key || gtp_token}`,
|
|
4647
|
+
'X-gtp-token': 'true',
|
|
4648
|
+
'Content-Type': 'application/json',
|
|
4649
|
+
},
|
|
4650
|
+
require_approval: 'never',
|
|
4651
|
+
}),
|
|
4652
|
+
);
|
|
4653
|
+
break;
|
|
4654
|
+
}
|
|
4654
4655
|
|
|
4655
|
-
|
|
4656
|
-
|
|
4657
|
-
|
|
4658
|
-
|
|
4659
|
-
|
|
4660
|
-
|
|
4661
|
-
|
|
4662
|
-
|
|
4663
|
-
|
|
4664
|
-
|
|
4665
|
-
|
|
4666
|
-
|
|
4667
|
-
|
|
4668
|
-
|
|
4669
|
-
|
|
4670
|
-
|
|
4671
|
-
|
|
4672
|
-
|
|
4673
|
-
|
|
4674
|
-
|
|
4656
|
+
case 'cpi': {
|
|
4657
|
+
try {
|
|
4658
|
+
debugger;
|
|
4659
|
+
const api_allow_methods = Object.keys(_conf.cpi_methods);
|
|
4660
|
+
for (const method_name of api_allow_methods || []) {
|
|
4661
|
+
const method_prop = _conf.cpi_methods[method_name];
|
|
4662
|
+
|
|
4663
|
+
if (!method_prop) continue;
|
|
4664
|
+
if (method_prop.private) continue;
|
|
4665
|
+
if (!method_prop.description) continue;
|
|
4666
|
+
|
|
4667
|
+
let inputSchema = {};
|
|
4668
|
+
|
|
4669
|
+
const get_z_item = function (key, val) {
|
|
4670
|
+
let prop = {};
|
|
4671
|
+
if (val.type === 'object' && val.items) {
|
|
4672
|
+
for (const [item_key, item_val] of Object.entries(val.items.properties)) {
|
|
4673
|
+
prop[item_key] = get_z_item(item_key, item_val);
|
|
4674
|
+
if (!val?.items?.required?.includes(item_key)) {
|
|
4675
|
+
prop[item_key] = prop[item_key].optional();
|
|
4676
|
+
}
|
|
4675
4677
|
}
|
|
4676
4678
|
}
|
|
4677
|
-
}
|
|
4678
4679
|
|
|
4679
|
-
|
|
4680
|
-
|
|
4681
|
-
|
|
4680
|
+
if (val.type === 'array') {
|
|
4681
|
+
prop = get_z_item('', val.items);
|
|
4682
|
+
}
|
|
4682
4683
|
|
|
4683
|
-
|
|
4684
|
+
let _z = z[val.type](prop);
|
|
4684
4685
|
|
|
4685
|
-
|
|
4686
|
-
|
|
4687
|
-
|
|
4686
|
+
if (!val.mandatory) {
|
|
4687
|
+
_z = _z.optional();
|
|
4688
|
+
}
|
|
4688
4689
|
|
|
4689
|
-
|
|
4690
|
-
|
|
4691
|
-
|
|
4690
|
+
if (val.enum) {
|
|
4691
|
+
_z = z.enum(val.enum);
|
|
4692
|
+
}
|
|
4692
4693
|
|
|
4693
|
-
|
|
4694
|
-
|
|
4695
|
-
|
|
4696
|
-
|
|
4697
|
-
|
|
4698
|
-
|
|
4699
|
-
|
|
4700
|
-
|
|
4694
|
+
let valid_values = '';
|
|
4695
|
+
if (val.options) {
|
|
4696
|
+
valid_values = val.options.join(', ');
|
|
4697
|
+
}
|
|
4698
|
+
if (val.description) {
|
|
4699
|
+
const desc = val.name || key.replace(/_/g, ' ').replace(/\b(\w)/g, (_, char) => char.toUpperCase());
|
|
4700
|
+
_z = _z.describe((desc ? desc + ' - ' : '') + val.description + (valid_values ? ' Valid values: ' + valid_values : ''));
|
|
4701
|
+
}
|
|
4701
4702
|
|
|
4702
|
-
|
|
4703
|
-
|
|
4703
|
+
return _z;
|
|
4704
|
+
};
|
|
4704
4705
|
|
|
4705
|
-
|
|
4706
|
-
|
|
4707
|
-
|
|
4708
|
-
|
|
4706
|
+
if (method_prop.fields) {
|
|
4707
|
+
try {
|
|
4708
|
+
for (const [key, val] of Object.entries(method_prop.fields)) {
|
|
4709
|
+
inputSchema[key] = get_z_item(key, val);
|
|
4710
|
+
}
|
|
4711
|
+
} catch (error) {
|
|
4712
|
+
debugger;
|
|
4709
4713
|
}
|
|
4714
|
+
}
|
|
4715
|
+
try {
|
|
4716
|
+
tools.push(
|
|
4717
|
+
tool({
|
|
4718
|
+
name: method_name.replace(/_/g, ' ').replace(/\b(\w)/g, (_, char) => char.toUpperCase()),
|
|
4719
|
+
description: method_prop.description,
|
|
4720
|
+
parameters: z.object(inputSchema),
|
|
4721
|
+
async execute(e, RunContext) {
|
|
4722
|
+
const params = e;
|
|
4723
|
+
try {
|
|
4724
|
+
const response = await fetch(`http://localhost:3007/cpi/${method_name}`, {
|
|
4725
|
+
method: 'POST',
|
|
4726
|
+
headers: {
|
|
4727
|
+
Accept: 'application/json',
|
|
4728
|
+
'Content-Type': 'application/json',
|
|
4729
|
+
},
|
|
4730
|
+
body: JSON.stringify({ ...params, ...{ gtp_token } }),
|
|
4731
|
+
});
|
|
4732
|
+
const ret = await response.json();
|
|
4733
|
+
return {
|
|
4734
|
+
content: [{ type: 'text', text: JSON.stringify(ret || '', null, 2) }],
|
|
4735
|
+
};
|
|
4736
|
+
} catch (err) {
|
|
4737
|
+
return 'unknown';
|
|
4738
|
+
}
|
|
4739
|
+
},
|
|
4740
|
+
}),
|
|
4741
|
+
);
|
|
4710
4742
|
} catch (error) {
|
|
4711
4743
|
debugger;
|
|
4712
4744
|
}
|
|
4713
4745
|
}
|
|
4714
|
-
|
|
4715
|
-
|
|
4716
|
-
tool({
|
|
4717
|
-
name: method_name.replace(/_/g, ' ').replace(/\b(\w)/g, (_, char) => char.toUpperCase()),
|
|
4718
|
-
description: method_prop.description,
|
|
4719
|
-
parameters: z.object(inputSchema),
|
|
4720
|
-
async execute(e, RunContext) {
|
|
4721
|
-
const params = e;
|
|
4722
|
-
try {
|
|
4723
|
-
const response = await fetch(`http://localhost:3007/cpi/${method_name}`, {
|
|
4724
|
-
method: 'POST',
|
|
4725
|
-
headers: {
|
|
4726
|
-
Accept: 'application/json',
|
|
4727
|
-
'Content-Type': 'application/json',
|
|
4728
|
-
},
|
|
4729
|
-
body: JSON.stringify({ ...params, ...{ gtp_token } }),
|
|
4730
|
-
});
|
|
4731
|
-
const ret = await response.json();
|
|
4732
|
-
return {
|
|
4733
|
-
content: [{ type: 'text', text: JSON.stringify(ret || '', null, 2) }],
|
|
4734
|
-
};
|
|
4735
|
-
} catch (err) {
|
|
4736
|
-
return 'unknown';
|
|
4737
|
-
}
|
|
4738
|
-
},
|
|
4739
|
-
}),
|
|
4740
|
-
);
|
|
4741
|
-
} catch (error) {
|
|
4742
|
-
debugger;
|
|
4743
|
-
}
|
|
4746
|
+
} catch (error) {
|
|
4747
|
+
debugger;
|
|
4744
4748
|
}
|
|
4745
|
-
|
|
4746
|
-
debugger;
|
|
4749
|
+
break;
|
|
4747
4750
|
}
|
|
4748
|
-
break;
|
|
4749
|
-
}
|
|
4750
4751
|
|
|
4751
|
-
|
|
4752
|
-
|
|
4753
|
-
|
|
4754
|
-
|
|
4755
|
-
|
|
4756
|
-
|
|
4757
|
-
|
|
4758
|
-
|
|
4759
|
-
|
|
4760
|
-
|
|
4761
|
-
|
|
4762
|
-
|
|
4763
|
-
|
|
4764
|
-
|
|
4765
|
-
|
|
4766
|
-
|
|
4767
|
-
|
|
4768
|
-
|
|
4769
|
-
|
|
4770
|
-
|
|
4771
|
-
|
|
4772
|
-
|
|
4773
|
-
|
|
4774
|
-
|
|
4775
|
-
|
|
4776
|
-
|
|
4777
|
-
|
|
4778
|
-
|
|
4779
|
-
|
|
4780
|
-
|
|
4781
|
-
|
|
4782
|
-
|
|
4783
|
-
// case 'image_generate': {
|
|
4784
|
-
// tools.push(
|
|
4785
|
-
// tool({
|
|
4786
|
-
// name,
|
|
4787
|
-
// description,
|
|
4788
|
-
// parameters: z.object({
|
|
4789
|
-
// prompt: z.string().describe('The prompt for the image.'),
|
|
4790
|
-
// numGenerations: z.number().int().describe('Number generations to image create.').default(3),
|
|
4791
|
-
// }),
|
|
4792
|
-
// async execute(e, RunContext) {
|
|
4793
|
-
// const { prompt, numGenerations = val?.image_generations } = e;
|
|
4794
|
-
// try {
|
|
4795
|
-
// const base64 = await create_image(prompt, undefined, undefined, numGenerations);
|
|
4796
|
-
// // console.log(base64);
|
|
4797
|
-
|
|
4798
|
-
// // return `<img src="data:image/jpg;base64,${base64}">`;
|
|
4799
|
-
// return ``;
|
|
4800
|
-
// } catch (err) {
|
|
4801
|
-
// return 'unknown';
|
|
4802
|
-
// }
|
|
4803
|
-
// },
|
|
4804
|
-
// }),
|
|
4805
|
-
// );
|
|
4806
|
-
// break;
|
|
4807
|
-
// }
|
|
4808
|
-
|
|
4809
|
-
case 'image_generate': {
|
|
4810
|
-
tools.push(
|
|
4811
|
-
tool({
|
|
4812
|
-
name,
|
|
4813
|
-
description,
|
|
4814
|
-
parameters: z.object({
|
|
4815
|
-
prompt: z.string().describe('The prompt for the image.'),
|
|
4816
|
-
numGenerations: z.number().int().describe('Number generations to image create.').default(3),
|
|
4817
|
-
}),
|
|
4818
|
-
async execute(e, RunContext) {
|
|
4819
|
-
const { prompt, numGenerations } = e;
|
|
4820
|
-
try {
|
|
4821
|
-
let imgTags = '';
|
|
4822
|
-
const images_arr = await create_and_upload_image_to_drive('workspace', 'Chat Images', prompt, numGenerations, uid, app_id, job_id, headers);
|
|
4823
|
-
for (const img_obj of images_arr) {
|
|
4824
|
-
imgTags += `<img src="${img_obj.file_url}" alt="${prompt}" style="max-width: 100%; border-radius: 8px;" />`;
|
|
4825
|
-
}
|
|
4752
|
+
// case 'web_search': {
|
|
4753
|
+
// tools.push(
|
|
4754
|
+
// tool({
|
|
4755
|
+
// name: name || val.type,
|
|
4756
|
+
// description: description || val.type,
|
|
4757
|
+
// parameters: z.object({
|
|
4758
|
+
// query: z.string().describe('The search query text.'),
|
|
4759
|
+
// numResults: z.number().int().describe('Number of top search results to return.').default(3),
|
|
4760
|
+
// }),
|
|
4761
|
+
// async execute(e, RunContext) {
|
|
4762
|
+
// const { query, numResults } = e;
|
|
4763
|
+
// try {
|
|
4764
|
+
// const searchUrl = `https://api.duckduckgo.com/?q=${encodeURIComponent(query)}&format=json&no_redirect=1`;
|
|
4765
|
+
// const response = await fetch(searchUrl);
|
|
4766
|
+
// const data = await response.json();
|
|
4767
|
+
|
|
4768
|
+
// // Simplify results
|
|
4769
|
+
// const results = (data.RelatedTopics || []).slice(0, numResults).map((item) => ({
|
|
4770
|
+
// title: item.Text,
|
|
4771
|
+
// url: item.FirstURL,
|
|
4772
|
+
// }));
|
|
4773
|
+
|
|
4774
|
+
// return JSON.stringify(results, null, 2);
|
|
4775
|
+
// } catch (err) {
|
|
4776
|
+
// return 'unknown';
|
|
4777
|
+
// }
|
|
4778
|
+
// },
|
|
4779
|
+
// }),
|
|
4780
|
+
// );
|
|
4781
|
+
// break;
|
|
4782
|
+
// }
|
|
4826
4783
|
|
|
4827
|
-
|
|
4828
|
-
|
|
4829
|
-
|
|
4830
|
-
|
|
4831
|
-
|
|
4832
|
-
|
|
4833
|
-
|
|
4834
|
-
)
|
|
4835
|
-
|
|
4836
|
-
|
|
4784
|
+
// case 'image_generate': {
|
|
4785
|
+
// tools.push(
|
|
4786
|
+
// tool({
|
|
4787
|
+
// name,
|
|
4788
|
+
// description,
|
|
4789
|
+
// parameters: z.object({
|
|
4790
|
+
// prompt: z.string().describe('The prompt for the image.'),
|
|
4791
|
+
// numGenerations: z.number().int().describe('Number generations to image create.').default(3),
|
|
4792
|
+
// }),
|
|
4793
|
+
// async execute(e, RunContext) {
|
|
4794
|
+
// const { prompt, numGenerations = val?.image_generations } = e;
|
|
4795
|
+
// try {
|
|
4796
|
+
// const base64 = await create_image(prompt, undefined, undefined, numGenerations);
|
|
4797
|
+
// // console.log(base64);
|
|
4798
|
+
|
|
4799
|
+
// // return `<img src="data:image/jpg;base64,${base64}">`;
|
|
4800
|
+
// return ``;
|
|
4801
|
+
// } catch (err) {
|
|
4802
|
+
// return 'unknown';
|
|
4803
|
+
// }
|
|
4804
|
+
// },
|
|
4805
|
+
// }),
|
|
4806
|
+
// );
|
|
4807
|
+
// break;
|
|
4808
|
+
// }
|
|
4837
4809
|
|
|
4838
|
-
|
|
4839
|
-
|
|
4840
|
-
|
|
4841
|
-
|
|
4842
|
-
|
|
4843
|
-
|
|
4844
|
-
|
|
4845
|
-
|
|
4846
|
-
|
|
4847
|
-
|
|
4848
|
-
|
|
4849
|
-
|
|
4850
|
-
|
|
4851
|
-
|
|
4852
|
-
|
|
4853
|
-
|
|
4854
|
-
|
|
4855
|
-
add_data_to_table_agent.asTool({
|
|
4856
|
-
toolName: 'add data to table',
|
|
4857
|
-
toolDescription: `add data to table`,
|
|
4858
|
-
}),
|
|
4859
|
-
);
|
|
4810
|
+
case 'image_generate': {
|
|
4811
|
+
tools.push(
|
|
4812
|
+
tool({
|
|
4813
|
+
name,
|
|
4814
|
+
description,
|
|
4815
|
+
parameters: z.object({
|
|
4816
|
+
prompt: z.string().describe('The prompt for the image.'),
|
|
4817
|
+
numGenerations: z.number().int().describe('Number generations to image create.').default(3),
|
|
4818
|
+
}),
|
|
4819
|
+
async execute(e, RunContext) {
|
|
4820
|
+
const { prompt, numGenerations } = e;
|
|
4821
|
+
try {
|
|
4822
|
+
let imgTags = '';
|
|
4823
|
+
const images_arr = await create_and_upload_image_to_drive('workspace', 'Chat Images', prompt, numGenerations, uid, app_id, job_id, headers);
|
|
4824
|
+
for (const img_obj of images_arr) {
|
|
4825
|
+
imgTags += `<img src="${img_obj.file_url}" alt="${prompt}" style="max-width: 100%; border-radius: 8px;" />`;
|
|
4826
|
+
}
|
|
4860
4827
|
|
|
4861
|
-
|
|
4862
|
-
|
|
4863
|
-
|
|
4864
|
-
|
|
4865
|
-
|
|
4866
|
-
|
|
4867
|
-
|
|
4828
|
+
return imgTags;
|
|
4829
|
+
} catch (err) {
|
|
4830
|
+
console.error('Image Tool Error:', err);
|
|
4831
|
+
return `Error generating image: ${err.message}`;
|
|
4832
|
+
}
|
|
4833
|
+
},
|
|
4834
|
+
}),
|
|
4835
|
+
);
|
|
4836
|
+
break;
|
|
4837
|
+
}
|
|
4868
4838
|
|
|
4869
|
-
|
|
4870
|
-
|
|
4871
|
-
|
|
4872
|
-
|
|
4873
|
-
|
|
4874
|
-
|
|
4875
|
-
|
|
4839
|
+
case 'table': {
|
|
4840
|
+
const table_id = val.prog_id;
|
|
4841
|
+
// prompt += ` for table_id: ${table_id}`;
|
|
4842
|
+
context.table_id = table_id;
|
|
4843
|
+
tools.push(get_studio_table_info_by_table_id_tool);
|
|
4844
|
+
//======== mock data ==========
|
|
4845
|
+
// const mock_data_generator_agent = get_mock_data_generator_agent(app_id, table_id);
|
|
4846
|
+
// tools.push(
|
|
4847
|
+
// mock_data_generator_agent.asTool({
|
|
4848
|
+
// toolName: 'Mock Data Generator',
|
|
4849
|
+
// toolDescription: `generate Mock Data to a table`,
|
|
4850
|
+
// }),
|
|
4851
|
+
// );
|
|
4852
|
+
// tools.push(get_studio_table_info_by_table_id_tool);
|
|
4853
|
+
|
|
4854
|
+
//======== add data ==========
|
|
4855
|
+
tools.push(
|
|
4856
|
+
add_data_to_table_agent.asTool({
|
|
4857
|
+
toolName: 'add data to table',
|
|
4858
|
+
toolDescription: `add data to table`,
|
|
4859
|
+
}),
|
|
4860
|
+
);
|
|
4876
4861
|
|
|
4877
|
-
|
|
4862
|
+
//======== fetch data ==========
|
|
4863
|
+
tools.push(
|
|
4864
|
+
fetch_table_data_agent.asTool({
|
|
4865
|
+
toolName: 'Fetch Table Data Agent',
|
|
4866
|
+
toolDescription: `fetch data from a table`,
|
|
4867
|
+
}),
|
|
4868
|
+
);
|
|
4878
4869
|
|
|
4879
|
-
|
|
4870
|
+
//======== delete data ==========
|
|
4871
|
+
tools.push(
|
|
4872
|
+
delete_table_doc.asTool({
|
|
4873
|
+
toolName: 'Delete Table Doc',
|
|
4874
|
+
toolDescription: `The tool delete document from the database, need to ask for table`,
|
|
4875
|
+
}),
|
|
4876
|
+
);
|
|
4880
4877
|
|
|
4881
|
-
|
|
4882
|
-
// tools.push(
|
|
4883
|
-
// add_data_to_table_agent.asTool({
|
|
4884
|
-
// toolName: 'add data to table',
|
|
4885
|
-
// toolDescription: `add data to table`,
|
|
4886
|
-
// }),
|
|
4887
|
-
// );
|
|
4878
|
+
// tools.push(create_table_management_tool);
|
|
4888
4879
|
|
|
4889
|
-
|
|
4890
|
-
}
|
|
4880
|
+
// tools.push(create_landing_page_tool);
|
|
4891
4881
|
|
|
4892
|
-
|
|
4893
|
-
|
|
4894
|
-
|
|
4895
|
-
|
|
4882
|
+
// const add_data_to_table_agent = get_add_data_to_table_agent(app_id, table_id);
|
|
4883
|
+
// tools.push(
|
|
4884
|
+
// add_data_to_table_agent.asTool({
|
|
4885
|
+
// toolName: 'add data to table',
|
|
4886
|
+
// toolDescription: `add data to table`,
|
|
4887
|
+
// }),
|
|
4888
|
+
// );
|
|
4896
4889
|
|
|
4897
|
-
|
|
4898
|
-
tools.push(fileSearchTool(val.youtube.vector_store_id));
|
|
4890
|
+
break;
|
|
4899
4891
|
}
|
|
4900
4892
|
|
|
4901
|
-
|
|
4902
|
-
|
|
4893
|
+
case 'file_search': {
|
|
4894
|
+
if (val?.file?.vector_store_id) {
|
|
4895
|
+
tools.push(fileSearchTool(val.file.vector_store_id));
|
|
4896
|
+
}
|
|
4903
4897
|
|
|
4904
|
-
|
|
4905
|
-
|
|
4906
|
-
|
|
4907
|
-
docType: 'studio',
|
|
4908
|
-
stat: 3,
|
|
4909
|
-
'properties.menuType': 'ai_agent',
|
|
4910
|
-
},
|
|
4911
|
-
limit: limit || 9999,
|
|
4912
|
-
};
|
|
4898
|
+
if (val?.youtube?.vector_store_id) {
|
|
4899
|
+
tools.push(fileSearchTool(val.youtube.vector_store_id));
|
|
4900
|
+
}
|
|
4913
4901
|
|
|
4914
|
-
|
|
4915
|
-
// add all agents if no agent id
|
|
4916
|
-
if (val.ai_agent_id) {
|
|
4917
|
-
opt.selector._id = val.ai_agent_id;
|
|
4902
|
+
break;
|
|
4918
4903
|
}
|
|
4919
4904
|
|
|
4920
|
-
|
|
4921
|
-
|
|
4922
|
-
|
|
4923
|
-
|
|
4924
|
-
|
|
4925
|
-
|
|
4926
|
-
|
|
4927
|
-
|
|
4928
|
-
|
|
4929
|
-
toolName: agent_doc.agent_name,
|
|
4930
|
-
toolDescription: agent_doc.agent_instructions,
|
|
4931
|
-
}),
|
|
4932
|
-
);
|
|
4933
|
-
}
|
|
4934
|
-
// const agent_ret = await get_ai_agents(opt);
|
|
4935
|
-
// if (agent_ret.code > -1) {
|
|
4936
|
-
// const agent_doc = agent_ret.data;
|
|
4905
|
+
case 'ai_agent': {
|
|
4906
|
+
let opt = {
|
|
4907
|
+
selector: {
|
|
4908
|
+
docType: 'studio',
|
|
4909
|
+
stat: 3,
|
|
4910
|
+
'properties.menuType': 'ai_agent',
|
|
4911
|
+
},
|
|
4912
|
+
limit: limit || 9999,
|
|
4913
|
+
};
|
|
4937
4914
|
|
|
4938
|
-
|
|
4939
|
-
|
|
4940
|
-
|
|
4941
|
-
|
|
4915
|
+
// let opt = {};
|
|
4916
|
+
// add all agents if no agent id
|
|
4917
|
+
if (val.ai_agent_id) {
|
|
4918
|
+
opt.selector._id = val.ai_agent_id;
|
|
4919
|
+
}
|
|
4942
4920
|
|
|
4943
|
-
|
|
4944
|
-
|
|
4945
|
-
|
|
4946
|
-
|
|
4947
|
-
|
|
4948
|
-
|
|
4949
|
-
|
|
4950
|
-
|
|
4951
|
-
|
|
4952
|
-
|
|
4953
|
-
|
|
4954
|
-
|
|
4955
|
-
|
|
4921
|
+
const user_agents = await db_module.find_app_couch_query(ai_agent_doc?.reference_doc?.studio_meta?.shared_from_app_id || ai_agent_doc?.reference_doc?.studio_meta?.installed_from_app_id || app_id, opt);
|
|
4922
|
+
for (const agent_doc of user_agents.docs) {
|
|
4923
|
+
const agent = new Agent({
|
|
4924
|
+
name: agent_doc.agent_name,
|
|
4925
|
+
instructions: agent_doc.agent_instructions,
|
|
4926
|
+
});
|
|
4927
|
+
|
|
4928
|
+
tools.push(
|
|
4929
|
+
agent.asTool({
|
|
4930
|
+
toolName: agent_doc.agent_name,
|
|
4931
|
+
toolDescription: agent_doc.agent_instructions,
|
|
4932
|
+
}),
|
|
4933
|
+
);
|
|
4934
|
+
}
|
|
4935
|
+
// const agent_ret = await get_ai_agents(opt);
|
|
4936
|
+
// if (agent_ret.code > -1) {
|
|
4937
|
+
// const agent_doc = agent_ret.data;
|
|
4938
|
+
|
|
4939
|
+
// const agent = new Agent({
|
|
4940
|
+
// name: agent_doc.agent_name,
|
|
4941
|
+
// instructions: agent_doc.agent_instructions,
|
|
4942
|
+
// });
|
|
4943
|
+
|
|
4944
|
+
// tools.push(
|
|
4945
|
+
// agent.asTool({
|
|
4946
|
+
// toolName: agent_doc.agent_name,
|
|
4947
|
+
// toolDescription: agent_doc.agent_instructions,
|
|
4948
|
+
// }),
|
|
4949
|
+
// );
|
|
4950
|
+
// }
|
|
4951
|
+
// }
|
|
4952
|
+
break;
|
|
4956
4953
|
}
|
|
4957
|
-
|
|
4958
|
-
|
|
4954
|
+
case 'plugin': {
|
|
4955
|
+
if (!val.plugin_id) {
|
|
4956
|
+
throw new Error('undefined plugin_id');
|
|
4957
|
+
}
|
|
4958
|
+
if (!val.method) {
|
|
4959
|
+
throw new Error('undefined method');
|
|
4960
|
+
}
|
|
4961
|
+
// const tool = await get_plugin_tool(app_id, uid, val.plugin_id, val.method, {});
|
|
4962
|
+
const tool = await get_plugin_tool(
|
|
4963
|
+
ai_agent_doc?.reference_doc?.studio_meta?.shared_from_app_id || ai_agent_doc?.reference_doc?.studio_meta?.installed_from_app_id || app_id,
|
|
4964
|
+
ai_agent_doc?.reference_doc?.studio_meta?.shared_from_uid || ai_agent_doc?.reference_doc?.studio_meta?.installed_from_uid || uid,
|
|
4965
|
+
val.plugin_id,
|
|
4966
|
+
val.method,
|
|
4967
|
+
{},
|
|
4968
|
+
);
|
|
4969
|
+
tools.push(tool);
|
|
4970
|
+
break;
|
|
4959
4971
|
}
|
|
4960
|
-
|
|
4961
|
-
|
|
4962
|
-
ai_agent_doc?.reference_doc?.studio_meta?.shared_from_app_id || ai_agent_doc?.reference_doc?.studio_meta?.installed_from_app_id || app_id,
|
|
4963
|
-
ai_agent_doc?.reference_doc?.studio_meta?.shared_from_uid || ai_agent_doc?.reference_doc?.studio_meta?.installed_from_uid || uid,
|
|
4964
|
-
val.plugin_id,
|
|
4965
|
-
val.method,
|
|
4966
|
-
{},
|
|
4967
|
-
);
|
|
4968
|
-
tools.push(tool);
|
|
4969
|
-
break;
|
|
4972
|
+
default:
|
|
4973
|
+
break;
|
|
4970
4974
|
}
|
|
4971
|
-
default:
|
|
4972
|
-
break;
|
|
4973
4975
|
}
|
|
4974
|
-
|
|
4975
|
-
|
|
4976
|
-
|
|
4977
|
-
|
|
4978
|
-
|
|
4979
|
-
|
|
4980
|
-
|
|
4981
|
-
|
|
4982
|
-
|
|
4983
|
-
|
|
4984
|
-
|
|
4985
|
-
|
|
4986
|
-
|
|
4987
|
-
});
|
|
4976
|
+
// if (!tools.length) continue;
|
|
4977
|
+
const agent = new Agent({
|
|
4978
|
+
name: ai_agent_doc._id,
|
|
4979
|
+
instructions: ai_agent_doc.agentConfig.agent_instructions + get_agent_instructions(),
|
|
4980
|
+
model,
|
|
4981
|
+
tools,
|
|
4982
|
+
metadata: {
|
|
4983
|
+
agent_id: ai_agent_doc._id,
|
|
4984
|
+
ts: Date.now(),
|
|
4985
|
+
},
|
|
4986
|
+
tool_resources,
|
|
4987
|
+
modelSettings,
|
|
4988
|
+
});
|
|
4988
4989
|
|
|
4989
|
-
|
|
4990
|
+
init_agent_hooks(agent);
|
|
4990
4991
|
|
|
4991
|
-
|
|
4992
|
+
list.push(agent);
|
|
4993
|
+
} catch (err) {}
|
|
4992
4994
|
}
|
|
4993
4995
|
//tell me more on xuda
|
|
4994
4996
|
// debugger;
|