@xuda.io/ai_module 1.1.4154 → 1.1.4156

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 +217 -212
  2. package/package.json +1 -1
package/index.mjs CHANGED
@@ -288,216 +288,216 @@ const fetch_data_tool = tool({
288
288
  },
289
289
  });
290
290
 
291
- const create_table_management_tool = tool({
292
- name: 'Create Table Management Program',
293
- description: 'this tool create table management program',
294
- parameters: z.object({}),
295
- async execute(e, RunContext) {
296
- const { app_id, uid, table_id, userName } = RunContext.context;
297
- try {
298
- const project_db = await get_project_db(app_id);
299
- let table_doc;
300
- try {
301
- table_doc = await project_db.get(table_id);
302
- } catch (error) {
303
- throw new Error(`table doc ${table_id} not found`);
304
- }
305
-
306
- const menuType = 'component';
307
- const parentId = 'programs';
308
- const checkedInUserName = userName;
309
- const name = `${table_doc.properties.menuName} ${table_doc.properties.menuName.includes('table') ? '' : 'table '}Management Program`;
310
- const doc = createDoc({ uid, properties: { menuType, menuName: name, menuTitle: name }, checkedInUserName, app_id, parentId });
311
-
312
- const progUi = [
313
- {
314
- id: 'root',
315
- type: 'element',
316
- tagName: 'xu-multi-view',
317
- attributes: {},
318
- children: [
319
- {
320
- type: 'element',
321
- tagName: 'div',
322
- attributes: {},
323
- children: [
324
- {
325
- type: 'element',
326
- tagName: 'xu-widget',
327
- attributes: {
328
- 'xu-widget': '@xuda.io/xuda-widget-plugin-ag-grid',
329
- 'xu-method': '_default',
330
- },
331
- children: [],
332
- id: `node-${crypto.randomUUID()}`,
333
- path: [0, 0, 0],
334
- $folded: false,
335
- code: '<xu-widget xu-widget="@xuda.io/xuda-widget-plugin-ag-grid" xu-method="_default"></xu-widget>',
336
- editCode: false,
337
- $childrenClass: 'active',
338
- $nodeBackClass: 'selected-tree rounded-lg',
339
- },
340
- ],
341
- id: `node-${crypto.randomUUID()}`,
342
- path: [0, 0],
343
- },
344
- ],
345
- path: [0],
346
- $folded: false,
347
- },
348
- ];
349
-
350
- const progDataSource = {
351
- dataSourceType: 'table',
352
- dataSourceFilterModelType: 'index',
353
- dataSourceSort: 'asc',
354
- dataSourceTableId: table_id,
355
- };
356
-
357
- doc.studio_meta.miniApp = true;
358
- doc.progUi = progUi;
359
- doc.progDataSource = progDataSource;
360
- doc.progFields = [];
361
-
362
- for (const field of table_doc.tableFields || []) {
363
- const field_id = field.data.field_id;
364
- const fieldType = field.props.fieldType;
365
-
366
- doc.progFields.push({
367
- id: Date.now(),
368
- data: {
369
- type: 'table',
370
- field_id,
371
- },
372
- props: {
373
- fieldType,
374
- propExpressions: {},
375
- },
376
- workflow: [],
377
- });
378
- }
379
-
380
- const result = await project_db.insert(doc);
381
-
382
- update_thumbnail('mini_app', doc, app_id);
383
-
384
- console.log('Create Table Management Component >>>> ', result);
385
- return result;
386
- } catch (err) {
387
- // console.error(err);
388
- return err.message;
389
- }
390
- },
391
- });
392
-
393
- const create_landing_page_tool = tool({
394
- name: 'Create Landing Page Program',
395
- description: 'this tool create landing page by subject',
396
- parameters: z.object({ subject: z.string().describe('describe the landing page in short') }),
397
- async execute(e, RunContext) {
398
- const { subject } = e;
399
- const { app_id, uid, table_id, userName, app_obj, account_info } = RunContext.context;
400
- try {
401
- const project_db = await get_project_db(app_id);
402
- let table_doc;
403
- try {
404
- table_doc = await project_db.get(table_id);
405
- } catch (error) {
406
- throw new Error(`table doc ${table_id} not found`);
407
- }
408
- debugger;
409
- const tableIndexObj = table_doc?.tableIndexes?.[0];
410
-
411
- if (_.isEmpty(tableIndexObj)) {
412
- throw new Error(`table have at least one index`);
413
- }
414
- const indexSegmentKey = tableIndexObj?.data?.keys?.[0];
415
-
416
- if (!indexSegmentKey) {
417
- throw new Error(`key segment is empty for the main index`);
418
- }
419
-
420
- const dataSourceIndexId = tableIndexObj?.id;
421
-
422
- if (!dataSourceIndexId) {
423
- throw new Error(`table have at least one index id`);
424
- }
425
-
426
- const title_ret = await submit_chat_gpt_prompt({ uid, prompt: `create title for ${subject} return 5 words result maximum text only without options `, model: 'gpt-5-nano' });
291
+ // const create_table_management_tool = tool({
292
+ // name: 'Create Table Management Program',
293
+ // description: 'this tool create table management program',
294
+ // parameters: z.object({}),
295
+ // async execute(e, RunContext) {
296
+ // const { app_id, uid, table_id, userName } = RunContext.context;
297
+ // try {
298
+ // const project_db = await get_project_db(app_id);
299
+ // let table_doc;
300
+ // try {
301
+ // table_doc = await project_db.get(table_id);
302
+ // } catch (error) {
303
+ // throw new Error(`table doc ${table_id} not found`);
304
+ // }
427
305
 
428
- const menuType = 'component';
429
- const parentId = 'programs';
430
- const checkedInUserName = userName;
431
- const name = `${title_ret.data} Landing Page`;
432
- const properties = { menuType, menuName: name, menuTitle: name, rwMode: 'U', uiFramework: '@xuda.io/xuda-framework-plugin-tailwind', renderType: 'form', allowCreate: true };
433
- const doc = createDoc({ uid, properties, checkedInUserName, app_id, parentId });
306
+ // const menuType = 'component';
307
+ // const parentId = 'programs';
308
+ // const checkedInUserName = userName;
309
+ // const name = `${table_doc.properties.menuName} ${table_doc.properties.menuName.includes('table') ? '' : 'table '}Management Program`;
310
+ // const doc = createDoc({ uid, properties: { menuType, menuName: name, menuTitle: name }, checkedInUserName, app_id, parentId });
311
+
312
+ // const progUi = [
313
+ // {
314
+ // id: 'root',
315
+ // type: 'element',
316
+ // tagName: 'xu-multi-view',
317
+ // attributes: {},
318
+ // children: [
319
+ // {
320
+ // type: 'element',
321
+ // tagName: 'div',
322
+ // attributes: {},
323
+ // children: [
324
+ // {
325
+ // type: 'element',
326
+ // tagName: 'xu-widget',
327
+ // attributes: {
328
+ // 'xu-widget': '@xuda.io/xuda-widget-plugin-ag-grid',
329
+ // 'xu-method': '_default',
330
+ // },
331
+ // children: [],
332
+ // id: `node-${crypto.randomUUID()}`,
333
+ // path: [0, 0, 0],
334
+ // $folded: false,
335
+ // code: '<xu-widget xu-widget="@xuda.io/xuda-widget-plugin-ag-grid" xu-method="_default"></xu-widget>',
336
+ // editCode: false,
337
+ // $childrenClass: 'active',
338
+ // $nodeBackClass: 'selected-tree rounded-lg',
339
+ // },
340
+ // ],
341
+ // id: `node-${crypto.randomUUID()}`,
342
+ // path: [0, 0],
343
+ // },
344
+ // ],
345
+ // path: [0],
346
+ // $folded: false,
347
+ // },
348
+ // ];
349
+
350
+ // const progDataSource = {
351
+ // dataSourceType: 'table',
352
+ // dataSourceFilterModelType: 'index',
353
+ // dataSourceSort: 'asc',
354
+ // dataSourceTableId: table_id,
355
+ // };
356
+
357
+ // doc.studio_meta.miniApp = true;
358
+ // doc.progUi = progUi;
359
+ // doc.progDataSource = progDataSource;
360
+ // doc.progFields = [];
361
+
362
+ // for (const field of table_doc.tableFields || []) {
363
+ // const field_id = field.data.field_id;
364
+ // const fieldType = field.props.fieldType;
365
+
366
+ // doc.progFields.push({
367
+ // id: Date.now(),
368
+ // data: {
369
+ // type: 'table',
370
+ // field_id,
371
+ // },
372
+ // props: {
373
+ // fieldType,
374
+ // propExpressions: {},
375
+ // },
376
+ // workflow: [],
377
+ // });
378
+ // }
434
379
 
435
- const progDataSource = {
436
- dataSourceType: 'table',
437
- dataSourceFilterModelType: 'index',
438
- dataSourceSort: 'asc',
439
- dataSourceTableId: table_id,
440
- dataSourceIndexId,
441
- dataSourceIndexesObj: {
442
- [dataSourceIndexId]: {
443
- [indexSegmentKey]: {
444
- from: 'Date.now()',
445
- locate_from: '',
446
- locate_to: '',
447
- to: 'Date.now()',
448
- key: indexSegmentKey,
449
- },
450
- },
451
- },
452
- };
380
+ // const result = await project_db.insert(doc);
453
381
 
454
- doc.studio_meta.miniApp = true;
382
+ // update_thumbnail('mini_app', doc, app_id);
455
383
 
456
- doc.progDataSource = progDataSource;
457
- doc.progFields = [];
384
+ // console.log('Create Table Management Component >>>> ', result);
385
+ // return result;
386
+ // } catch (err) {
387
+ // // console.error(err);
388
+ // return err.message;
389
+ // }
390
+ // },
391
+ // });
392
+
393
+ // const create_landing_page_tool = tool({
394
+ // name: 'Create Landing Page Program',
395
+ // description: 'this tool create landing page by subject',
396
+ // parameters: z.object({ subject: z.string().describe('describe the landing page in short') }),
397
+ // async execute(e, RunContext) {
398
+ // const { subject } = e;
399
+ // const { app_id, uid, table_id, userName, app_obj, account_info } = RunContext.context;
400
+ // try {
401
+ // const project_db = await get_project_db(app_id);
402
+ // let table_doc;
403
+ // try {
404
+ // table_doc = await project_db.get(table_id);
405
+ // } catch (error) {
406
+ // throw new Error(`table doc ${table_id} not found`);
407
+ // }
408
+ // debugger;
409
+ // const tableIndexObj = table_doc?.tableIndexes?.[0];
458
410
 
459
- let contactFormFields = [];
411
+ // if (_.isEmpty(tableIndexObj)) {
412
+ // throw new Error(`table have at least one index`);
413
+ // }
414
+ // const indexSegmentKey = tableIndexObj?.data?.keys?.[0];
460
415
 
461
- for (const field of table_doc.tableFields || []) {
462
- const field_id = field.data.field_id;
463
- const fieldType = field.props.fieldType;
464
- contactFormFields.push({ field_id, fieldType });
465
- doc.progFields.push({
466
- id: Date.now(),
467
- data: {
468
- type: 'table',
469
- field_id,
470
- },
471
- props: {
472
- fieldType,
473
- propExpressions: {},
474
- },
475
- workflow: [],
476
- });
477
- }
416
+ // if (!indexSegmentKey) {
417
+ // throw new Error(`key segment is empty for the main index`);
418
+ // }
478
419
 
479
- const html_ret = await submit_chat_gpt_prompt({
480
- uid,
481
- prompt: `Create a single-page landing layout with a Tailwind-styled contact form (fields: ${JSON.stringify(contactFormFields)}, subject: ${subject}). No navigation. Return only the <body> content. contact info:${JSON.stringify(account_info)} ${JSON.stringify(app_obj.app_general_prop)}`,
482
- model: 'gpt-5-nano',
483
- });
484
- debugger;
485
- const progUi = xudaPrase(html_ret.data);
486
- doc.progUi = progUi;
487
- doc.html = html_ret.data;
420
+ // const dataSourceIndexId = tableIndexObj?.id;
488
421
 
489
- const result = await project_db.insert(doc);
422
+ // if (!dataSourceIndexId) {
423
+ // throw new Error(`table have at least one index id`);
424
+ // }
490
425
 
491
- update_thumbnail('mini_app', doc, app_id);
426
+ // const title_ret = await submit_chat_gpt_prompt({ uid, prompt: `create title for ${subject} return 5 words result maximum text only without options `, model: 'gpt-5-nano' });
427
+
428
+ // const menuType = 'component';
429
+ // const parentId = 'programs';
430
+ // const checkedInUserName = userName;
431
+ // const name = `${title_ret.data} Landing Page`;
432
+ // const properties = { menuType, menuName: name, menuTitle: name, rwMode: 'U', uiFramework: '@xuda.io/xuda-framework-plugin-tailwind', renderType: 'form', allowCreate: true };
433
+ // const doc = createDoc({ uid, properties, checkedInUserName, app_id, parentId });
434
+
435
+ // const progDataSource = {
436
+ // dataSourceType: 'table',
437
+ // dataSourceFilterModelType: 'index',
438
+ // dataSourceSort: 'asc',
439
+ // dataSourceTableId: table_id,
440
+ // dataSourceIndexId,
441
+ // dataSourceIndexesObj: {
442
+ // [dataSourceIndexId]: {
443
+ // [indexSegmentKey]: {
444
+ // from: 'Date.now()',
445
+ // locate_from: '',
446
+ // locate_to: '',
447
+ // to: 'Date.now()',
448
+ // key: indexSegmentKey,
449
+ // },
450
+ // },
451
+ // },
452
+ // };
453
+
454
+ // doc.studio_meta.miniApp = true;
455
+
456
+ // doc.progDataSource = progDataSource;
457
+ // doc.progFields = [];
458
+
459
+ // let contactFormFields = [];
460
+
461
+ // for (const field of table_doc.tableFields || []) {
462
+ // const field_id = field.data.field_id;
463
+ // const fieldType = field.props.fieldType;
464
+ // contactFormFields.push({ field_id, fieldType });
465
+ // doc.progFields.push({
466
+ // id: Date.now(),
467
+ // data: {
468
+ // type: 'table',
469
+ // field_id,
470
+ // },
471
+ // props: {
472
+ // fieldType,
473
+ // propExpressions: {},
474
+ // },
475
+ // workflow: [],
476
+ // });
477
+ // }
492
478
 
493
- console.log('Create Landing Page >>>> ', result);
494
- return result;
495
- } catch (err) {
496
- // console.error(err);
497
- return err.message;
498
- }
499
- },
500
- });
479
+ // const html_ret = await submit_chat_gpt_prompt({
480
+ // uid,
481
+ // prompt: `Create a single-page landing layout with a Tailwind-styled contact form (fields: ${JSON.stringify(contactFormFields)}, subject: ${subject}). No navigation. Return only the <body> content. contact info:${JSON.stringify(account_info)} ${JSON.stringify(app_obj.app_general_prop)}`,
482
+ // model: 'gpt-5-nano',
483
+ // });
484
+ // debugger;
485
+ // const progUi = xudaPrase(html_ret.data);
486
+ // doc.progUi = progUi;
487
+ // doc.html = html_ret.data;
488
+
489
+ // const result = await project_db.insert(doc);
490
+
491
+ // update_thumbnail('mini_app', doc, app_id);
492
+
493
+ // console.log('Create Landing Page >>>> ', result);
494
+ // return result;
495
+ // } catch (err) {
496
+ // // console.error(err);
497
+ // return err.message;
498
+ // }
499
+ // },
500
+ // });
501
501
 
502
502
  const create_index_tool = tool({
503
503
  name: 'Create Index',
@@ -1899,7 +1899,7 @@ export const get_ai_chats = async function (req, job_id, headers) {
1899
1899
 
1900
1900
  if (!doc.chat_image && (!doc.thumbnail_request_ts || Date.now() - doc.thumbnail_request_ts > 120000)) {
1901
1901
  if (headers) {
1902
- update_thumbnail('conversation', doc, app_id, uid, job_id, headers);
1902
+ update_thumbnail('conversation', doc, account_profile_info.app_id, uid, job_id, headers);
1903
1903
  }
1904
1904
  }
1905
1905
 
@@ -2738,8 +2738,10 @@ export const update_ai_agent = async function (req, job_id, headers) {
2738
2738
 
2739
2739
  const app_id = await account_module.get_account_default_project_id(uid);
2740
2740
 
2741
+ const account_profile_info = await account_module.get_active_account_profile_info(uid);
2742
+
2741
2743
  try {
2742
- let agent_doc = await await db_module.get_app_couch_doc_native(app_id, agent_id);
2744
+ let agent_doc = await await db_module.get_app_couch_doc_native(account_profile_info.app_id, agent_id);
2743
2745
 
2744
2746
  agent_doc.ts = Date.now();
2745
2747
  agent_doc.agentConfig = agentConfig;
@@ -2759,12 +2761,12 @@ export const update_ai_agent = async function (req, job_id, headers) {
2759
2761
  agent_doc.studio_meta.agent_tags = agentConfig.agent_tags;
2760
2762
  agent_doc.studio_meta.agent_user_guide = agentConfig.agent_user_guide;
2761
2763
 
2762
- const data = await db_module.save_app_couch_doc_native(app_id, agent_doc);
2764
+ const data = await db_module.save_app_couch_doc_native(account_profile_info.app_id, agent_doc);
2763
2765
 
2764
2766
  setTimeout(async () => {
2765
- await update_ai_agent_properties(agent_doc, app_id, uid, { name_changed, agent_user_guide_changed, agent_category_changed, agent_subcategory_changed, agent_instructions_changed });
2767
+ await update_ai_agent_properties(agent_doc, account_profile_info.app_id, uid, { name_changed, agent_user_guide_changed, agent_category_changed, agent_subcategory_changed, agent_instructions_changed });
2766
2768
  if (name_changed) {
2767
- await update_thumbnail('ai_agent', agent_doc, app_id, uid, job_id, headers);
2769
+ await update_thumbnail('ai_agent', agent_doc, account_profile_info.app_id, uid, job_id, headers);
2768
2770
  }
2769
2771
  }, 500);
2770
2772
 
@@ -3116,6 +3118,8 @@ export const create_ai_agent = async function (req, job_id, headers) {
3116
3118
 
3117
3119
  const { account_project_id: app_id, account_info } = await account_module.get_default_project_account_doc(uid);
3118
3120
 
3121
+ const account_profile_info = await account_module.get_active_account_profile_info(uid);
3122
+
3119
3123
  try {
3120
3124
  const param = { uid, properties: { menuName: agentConfig.agent_name, menuTitle: agentConfig.agent_name, menuType: 'ai_agent' }, checkedInUserName: account_info.first_name + ' ' + account_info.last_name, app_id, parentId: 'ai_agents' };
3121
3125
  var agent_doc = createDoc(param);
@@ -3129,10 +3133,10 @@ export const create_ai_agent = async function (req, job_id, headers) {
3129
3133
 
3130
3134
  // const data = await db.insert(agent_doc);
3131
3135
 
3132
- const data = await db_module.save_app_couch_doc_native(app_id, agent_doc);
3136
+ const data = await db_module.save_app_couch_doc_native(account_profile_info.app_id, agent_doc);
3133
3137
  setTimeout(async () => {
3134
- await update_ai_agent_properties(agent_doc, app_id, uid);
3135
- await update_thumbnail('ai_agent', agent_doc, app_id, uid, job_id, headers);
3138
+ await update_ai_agent_properties(agent_doc, account_profile_info.app_id, uid);
3139
+ await update_thumbnail('ai_agent', agent_doc, account_profile_info.app_id, uid, job_id, headers);
3136
3140
  }, 500);
3137
3141
 
3138
3142
  upload_agent_files(uid, agent_doc);
@@ -3300,7 +3304,7 @@ export const update_ai_agent_properties = async function (doc, app_id, uid, fiel
3300
3304
  return save_ret;
3301
3305
  };
3302
3306
 
3303
- export const update_thumbnail = async function (type, doc, app_id, uid, job_id, headers, xuda_db, tags) {
3307
+ export const update_thumbnail = async function (type, doc, app_id, uid, job_id, headers, xuda_db, tags, account_profile_info) {
3304
3308
  let prompt = '';
3305
3309
 
3306
3310
  // setTimeout(async () => {
@@ -4190,7 +4194,7 @@ export const create_conversation = async function (req, job_id, headers) {
4190
4194
 
4191
4195
  await db_module.save_app_couch_doc_native(account_profile_info.app_id, conversation_doc);
4192
4196
 
4193
- await update_thumbnail('conversation', conversation_doc, app_id, uid, job_id, headers);
4197
+ await update_thumbnail('conversation', conversation_doc, account_profile_info.app_id, uid, job_id, headers, null, null, account_profile_info);
4194
4198
 
4195
4199
  if (conversation_doc.reference_type === 'contacts') {
4196
4200
  if (contact_uid_chat_conversation) {
@@ -6307,6 +6311,7 @@ export const create_mini_app = async function (req, job_id, headers) {
6307
6311
  const { uid, prompt } = req;
6308
6312
  try {
6309
6313
  const { account_project_id: app_id, account_info } = await account_module.get_default_project_account_doc(uid);
6314
+ const account_profile_info = await account_module.get_active_account_profile_info(uid);
6310
6315
 
6311
6316
  const param = { uid, properties: { menuName: prompt, menuTitle: prompt, menuType: 'component' }, checkedInUserName: account_info.first_name + ' ' + account_info.last_name, app_id, parentId: 'programs' };
6312
6317
  let component_doc = createDoc(param);
@@ -6315,9 +6320,9 @@ export const create_mini_app = async function (req, job_id, headers) {
6315
6320
  const name = await submit_chat_gpt_prompt({ uid, prompt: `create title for the prompt return 5 words result maximum text only without options : ${prompt}`, model: 'gpt-5-nano', metadata: { prog_id: component_doc._id, func: 'create_mini_app' } });
6316
6321
  component_doc.properties.menuName = name.data;
6317
6322
  component_doc.properties.menuTitle = name.data;
6318
- const data = await db_module.save_app_couch_doc_native(app_id, component_doc);
6323
+ const data = await db_module.save_app_couch_doc_native(account_profile_info.app_id, component_doc);
6319
6324
  setTimeout(async () => {
6320
- await update_thumbnail('mini_app', component_doc, app_id, uid, job_id, headers);
6325
+ await update_thumbnail('mini_app', component_doc, account_profile_info.app_id, uid, job_id, headers, null, null, account_profile_info);
6321
6326
  }, 500);
6322
6327
 
6323
6328
  data.doc = component_doc;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xuda.io/ai_module",
3
- "version": "1.1.4154",
3
+ "version": "1.1.4156",
4
4
  "description": "Xuda AI Module",
5
5
  "main": "index.mjs",
6
6
  "type": "module",