@xuda.io/ai_module 1.1.4804 → 1.1.4806
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 +0 -650
- package/old.mjs +655 -0
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -1069,656 +1069,6 @@ const check_studio_doc_tool = tool({
|
|
|
1069
1069
|
},
|
|
1070
1070
|
});
|
|
1071
1071
|
|
|
1072
|
-
// export const submit_agentic_studio_chat_gpt_prompt = async function (req) {
|
|
1073
|
-
// try {
|
|
1074
|
-
// const { user_prompt, object_unit = 'app', uid, app_id } = req;
|
|
1075
|
-
// // const model = 'ft:gpt-4o-2024-08-06:xuda-io:vps-hosting-plans:CDaxQiXo'; // 'gpt-4o'; //'gpt-4.1'; //
|
|
1076
|
-
|
|
1077
|
-
// const app_obj = await get_app_obj(app_id);
|
|
1078
|
-
|
|
1079
|
-
// // let check_results = {};
|
|
1080
|
-
// const auth = async function () {
|
|
1081
|
-
// if (app_obj.app_uId !== uid) {
|
|
1082
|
-
// const db_team = get_xuda_couch('xuda_team');
|
|
1083
|
-
// let master_auth_users = await db_team.view('xuda', 'user_active_shares', {
|
|
1084
|
-
// key: [uid, app_id],
|
|
1085
|
-
// });
|
|
1086
|
-
// if (!master_auth_users.rows.includes(uid)) {
|
|
1087
|
-
// throw new Error('user unauthorized');
|
|
1088
|
-
// }
|
|
1089
|
-
// }
|
|
1090
|
-
// };
|
|
1091
|
-
|
|
1092
|
-
// await auth();
|
|
1093
|
-
|
|
1094
|
-
// const userName = await get_user_name(uid);
|
|
1095
|
-
|
|
1096
|
-
// const get_zod_unit_schema = function (type) {
|
|
1097
|
-
// init(app_obj, {}, _, true, null, null, UglifyJS, JSON5, _conf, false, z);
|
|
1098
|
-
// const schema = get_zod_schema(type);
|
|
1099
|
-
// const jsonSchema = zodToJsonSchema(schema);
|
|
1100
|
-
// return JSON.stringify(jsonSchema, null, 2);
|
|
1101
|
-
// };
|
|
1102
|
-
|
|
1103
|
-
// const get_app_instructions = function (object_unit) {
|
|
1104
|
-
// return `
|
|
1105
|
-
// ### context ###
|
|
1106
|
-
// uid=${uid}
|
|
1107
|
-
// app_id=${app_id}
|
|
1108
|
-
|
|
1109
|
-
// ### Persona & Role ###
|
|
1110
|
-
// - You are a helpful and professional technical assistant named ${object_unit} builder.
|
|
1111
|
-
|
|
1112
|
-
// ### Tasks ###
|
|
1113
|
-
|
|
1114
|
-
// Your job is to assist the user with creating a ${user_prompt} that includes all tasks needed.
|
|
1115
|
-
|
|
1116
|
-
// ### workflow ###
|
|
1117
|
-
|
|
1118
|
-
// Steps:
|
|
1119
|
-
// 1. list all the tables needed for the task.
|
|
1120
|
-
// 2. prefix each table with the subject of the ${user_prompt} (e.g: CRM - Tasks).
|
|
1121
|
-
// 3. iterate the table list and build tables array using the Table builder tool, add the Table builder tool results and the table name in array RESULTS_ARR.
|
|
1122
|
-
|
|
1123
|
-
// ### Additional information ###
|
|
1124
|
-
|
|
1125
|
-
// ### Output ###
|
|
1126
|
-
// return the RESULTS_ARR Array.
|
|
1127
|
-
|
|
1128
|
-
// ### Examples ###
|
|
1129
|
-
|
|
1130
|
-
// `;
|
|
1131
|
-
// };
|
|
1132
|
-
|
|
1133
|
-
// const get_table_instructions = function (object_unit) {
|
|
1134
|
-
// return `
|
|
1135
|
-
// ### context ###
|
|
1136
|
-
// uid=${uid}
|
|
1137
|
-
// app_id=${app_id}
|
|
1138
|
-
|
|
1139
|
-
// ### Persona & Role ###
|
|
1140
|
-
// - You are a helpful and professional technical assistant named ${object_unit} builder.
|
|
1141
|
-
|
|
1142
|
-
// ### Tasks ###
|
|
1143
|
-
|
|
1144
|
-
// Your job is to assist the user with creating a ${user_prompt} that includes a full set of fields according to the provided ${object_unit} structure.
|
|
1145
|
-
|
|
1146
|
-
// - You must include all relevant fields a typical ${user_prompt} would require
|
|
1147
|
-
// - Add **multiple entries** in the "tableFields" array as needed to fully represent the structure.
|
|
1148
|
-
// - Follow the format and conventions shown in the ${object_unit} structure example.
|
|
1149
|
-
// - use uid for "createdByUid" and "checkedInUserId"
|
|
1150
|
-
|
|
1151
|
-
// ### workflow ###
|
|
1152
|
-
|
|
1153
|
-
// Steps:
|
|
1154
|
-
// 1. Use create_initial_studio_doc_tool to create the initial doc assign the return result in "doc" variable.
|
|
1155
|
-
|
|
1156
|
-
// 3. Use check_studio_doc_tool to check the ${object_unit} send the ${object_unit} as the doc, fix the issues if needed. if the check fail for 3 times the throw error, skip **Save Doc** tool if errors exist
|
|
1157
|
-
// 4. Use **Save Doc** tool to save the ${object_unit} doc and update the result in save_result variable,NEVER save if errors exist after check_studio_doc_tool
|
|
1158
|
-
|
|
1159
|
-
// ### Output ###
|
|
1160
|
-
// if success: {code:1,data:save_result}
|
|
1161
|
-
// if fail: {code:-1,data:error}
|
|
1162
|
-
|
|
1163
|
-
// ### EXAMPLE
|
|
1164
|
-
|
|
1165
|
-
// {
|
|
1166
|
-
// "_id": "5b1_tbl_47f0ac6059ca",
|
|
1167
|
-
// "app_id": "prj3937cb6f9a31c8c7dea25055bba845b1",
|
|
1168
|
-
// "stat": 3,
|
|
1169
|
-
// "docType": "studio",
|
|
1170
|
-
// "docDate": 1714916369797,
|
|
1171
|
-
// "ts": 1762953659001,
|
|
1172
|
-
// "order_ts": 1714916369797,
|
|
1173
|
-
// "studio_meta": {
|
|
1174
|
-
// "created": 1714916369797,
|
|
1175
|
-
// "createdByUid": "341cf2d32991a68e4d8aaba6c16e15cc",
|
|
1176
|
-
// "checkedInUserId": "341cf2d32991a68e4d8aaba6c16e15cc",
|
|
1177
|
-
// "checkedInUserName": "Ioshka Media",
|
|
1178
|
-
// "parentId": "database",
|
|
1179
|
-
// "savedByUid": "341cf2d32991a68e4d8aaba6c16e15cc"
|
|
1180
|
-
// },
|
|
1181
|
-
// "properties": {
|
|
1182
|
-
// "menuType": "table",
|
|
1183
|
-
// "menuName": "PT - Practice Table",
|
|
1184
|
-
// "databaseSocket": "@xuda.io/xuda-dbs-plugin-xuda",
|
|
1185
|
-
// "menuTitle": "PT - Practice Table"
|
|
1186
|
-
// },
|
|
1187
|
-
// "tableIndexes": [
|
|
1188
|
-
// {
|
|
1189
|
-
// "id": "76bbf201-997e-402c-b435-0649cc25d117",
|
|
1190
|
-
// "data": {
|
|
1191
|
-
// "name": "Primary_Index",
|
|
1192
|
-
// "unique": true,
|
|
1193
|
-
// "keys": [
|
|
1194
|
-
// "PT_Id"
|
|
1195
|
-
// ]
|
|
1196
|
-
// },
|
|
1197
|
-
// "props": {} <-- must appear even if empty
|
|
1198
|
-
// },
|
|
1199
|
-
// {
|
|
1200
|
-
// "id": "89f1609d-de4e-4b61-9357-284b1261314c",
|
|
1201
|
-
// "data": {
|
|
1202
|
-
// "name": "Index_2",
|
|
1203
|
-
// "unique": false,
|
|
1204
|
-
// "keys": [
|
|
1205
|
-
// "PT_Stat",
|
|
1206
|
-
// "PT_Group_Id"
|
|
1207
|
-
// ]
|
|
1208
|
-
// },
|
|
1209
|
-
// "props": {} <-- must appear even if empty
|
|
1210
|
-
// }
|
|
1211
|
-
// ],
|
|
1212
|
-
// "tableFields": [
|
|
1213
|
-
// {
|
|
1214
|
-
// "id": "b41aa880-56ec-4029-a21b-60c89a52b62e",
|
|
1215
|
-
// "data": {
|
|
1216
|
-
// "field_id": "PT_Id"
|
|
1217
|
-
// },
|
|
1218
|
-
// "props": {
|
|
1219
|
-
// "label":"Practice Id",
|
|
1220
|
-
// "fieldType": "string",
|
|
1221
|
-
// "mandatory": true
|
|
1222
|
-
// }
|
|
1223
|
-
|
|
1224
|
-
// },
|
|
1225
|
-
// {
|
|
1226
|
-
// "id": "8aec82db-35d9-4828-9fc7-49373c531cc3",
|
|
1227
|
-
// "data": {
|
|
1228
|
-
// "field_id": "PT_Type"
|
|
1229
|
-
// },
|
|
1230
|
-
// "props": {
|
|
1231
|
-
// "label":"Practice Type",
|
|
1232
|
-
// "fieldType": "string",
|
|
1233
|
-
// "mandatory": true
|
|
1234
|
-
// }
|
|
1235
|
-
|
|
1236
|
-
// },
|
|
1237
|
-
// {
|
|
1238
|
-
// "id": "d27c56e5-faec-4a0a-ad42-7bf55f8c67b3",
|
|
1239
|
-
// "data": {
|
|
1240
|
-
// "field_id": "PT_Stat"
|
|
1241
|
-
// },
|
|
1242
|
-
// "props": {
|
|
1243
|
-
// "label":"Practice Status",
|
|
1244
|
-
// "fieldType": "number",
|
|
1245
|
-
// "fieldComment": "1 = Draft\n2 = Private\n3 = Public\n4 = Deleted",
|
|
1246
|
-
// "mandatory": true
|
|
1247
|
-
// }
|
|
1248
|
-
|
|
1249
|
-
// },
|
|
1250
|
-
// {
|
|
1251
|
-
// "id": "659fbfb3-7dcc-4ea0-b1e9-5dd9553a99fc",
|
|
1252
|
-
// "data": {
|
|
1253
|
-
// "field_id": "PT_Question"
|
|
1254
|
-
// },
|
|
1255
|
-
// "props": {
|
|
1256
|
-
// "label":"Practice Question",
|
|
1257
|
-
// "fieldType": "string"
|
|
1258
|
-
// }
|
|
1259
|
-
|
|
1260
|
-
// },
|
|
1261
|
-
// {
|
|
1262
|
-
// "id": "080c8ceb-5a51-437b-8ad1-9fc005c79011",
|
|
1263
|
-
// "data": {
|
|
1264
|
-
// "field_id": "PT_Options"
|
|
1265
|
-
// },
|
|
1266
|
-
// "props": {
|
|
1267
|
-
// "label":"Practice Options",
|
|
1268
|
-
// "fieldType": "array"
|
|
1269
|
-
// }
|
|
1270
|
-
|
|
1271
|
-
// },
|
|
1272
|
-
// {
|
|
1273
|
-
// "id": "72c04aac-b3e7-4e7a-8a74-31075de3dbec",
|
|
1274
|
-
// "data": {
|
|
1275
|
-
// "field_id": "PT_Answer"
|
|
1276
|
-
// },
|
|
1277
|
-
// "props": {
|
|
1278
|
-
// "label":"Practice Answer",
|
|
1279
|
-
// "fieldType": "string"
|
|
1280
|
-
// }
|
|
1281
|
-
|
|
1282
|
-
// },
|
|
1283
|
-
// {
|
|
1284
|
-
// "id": "e37b08c6-f340-425a-bf01-809b28a486d3",
|
|
1285
|
-
// "data": {
|
|
1286
|
-
// "field_id": "PT_Matching_Answer"
|
|
1287
|
-
// },
|
|
1288
|
-
// "props": {
|
|
1289
|
-
// "label":"Practice Matching Answer",
|
|
1290
|
-
// "fieldType": "object"
|
|
1291
|
-
// },
|
|
1292
|
-
|
|
1293
|
-
// },
|
|
1294
|
-
// {
|
|
1295
|
-
// "id": "8ca4ace1-2010-45be-b7aa-2672ce0e6fea",
|
|
1296
|
-
// "data": {
|
|
1297
|
-
// "field_id": "PT_Group_Id"
|
|
1298
|
-
// },
|
|
1299
|
-
// "props": {
|
|
1300
|
-
// "label":"Practice Group Id",
|
|
1301
|
-
// "fieldType": "string"
|
|
1302
|
-
// }
|
|
1303
|
-
|
|
1304
|
-
// },
|
|
1305
|
-
// {
|
|
1306
|
-
// "id": "ae749c6d-1f39-4750-b79e-f016d50b8a11",
|
|
1307
|
-
// "data": {
|
|
1308
|
-
// "field_id": "PT_Difficulty"
|
|
1309
|
-
// },
|
|
1310
|
-
// "props": {
|
|
1311
|
-
// "label":"Practice Difficulty",
|
|
1312
|
-
// "fieldType": "number"
|
|
1313
|
-
// },
|
|
1314
|
-
|
|
1315
|
-
// },
|
|
1316
|
-
// {
|
|
1317
|
-
// "id": "5c5e7cb5-feee-4bc7-9d94-0ccd04a5eb06",
|
|
1318
|
-
// "data": {
|
|
1319
|
-
// "field_id": "PT_Uid"
|
|
1320
|
-
// },
|
|
1321
|
-
// "props": {
|
|
1322
|
-
// "label":"Practice User Id",
|
|
1323
|
-
// "fieldType": "string"
|
|
1324
|
-
// }
|
|
1325
|
-
|
|
1326
|
-
// }
|
|
1327
|
-
// ]
|
|
1328
|
-
// }
|
|
1329
|
-
// `;
|
|
1330
|
-
// };
|
|
1331
|
-
|
|
1332
|
-
// const get_folder_instructions = function (object_unit) {
|
|
1333
|
-
// return `
|
|
1334
|
-
// ### context ###
|
|
1335
|
-
// uid=${uid}
|
|
1336
|
-
// app_id=${app_id}
|
|
1337
|
-
|
|
1338
|
-
// ### Persona & Role ###
|
|
1339
|
-
// - You are a helpful and professional technical assistant named ${object_unit} builder.
|
|
1340
|
-
|
|
1341
|
-
// ### Tasks ###
|
|
1342
|
-
|
|
1343
|
-
// Your job is to assist the user with creating a ${user_prompt}.
|
|
1344
|
-
|
|
1345
|
-
// - Follow the format and conventions shown in the ${object_unit} structure example.
|
|
1346
|
-
// - use uid for "createdByUid" and "checkedInUserId"
|
|
1347
|
-
|
|
1348
|
-
// ### workflow ###
|
|
1349
|
-
|
|
1350
|
-
// Steps:
|
|
1351
|
-
// 1. Use create_initial_studio_doc_tool to create the initial doc assign the return result in "doc" variable.
|
|
1352
|
-
// 2. Get the ${object_unit} structure example from ### Structure and Examples ### section.
|
|
1353
|
-
// 3. Build the ${object_unit} and validate against vs_68af4c84631c81919709268c2d0f1687
|
|
1354
|
-
// 4. Use check_studio_doc_tool to check the ${object_unit} send the ${object_unit} as the doc, fix the issues if needed. if the check fail for 3 times the throw error, skip **Save Doc** tool if errors exist
|
|
1355
|
-
// 5. Use **Save Doc** tool to save the ${object_unit} doc and update the result in save_result variable,NEVER save if errors exist after check_studio_doc_tool
|
|
1356
|
-
|
|
1357
|
-
// ### Additional information ###
|
|
1358
|
-
// ${studio_units[object_unit].short}
|
|
1359
|
-
|
|
1360
|
-
// ### Output ###
|
|
1361
|
-
// if success: {code:1,data:save_result}
|
|
1362
|
-
// if fail: {code:-1,data:error}
|
|
1363
|
-
// `;
|
|
1364
|
-
// };
|
|
1365
|
-
|
|
1366
|
-
// const get_component_instructions = function (object_unit) {
|
|
1367
|
-
// return `
|
|
1368
|
-
// ### context ###
|
|
1369
|
-
// uid=${uid}
|
|
1370
|
-
// app_id=${app_id}
|
|
1371
|
-
|
|
1372
|
-
// ### Persona & Role ###
|
|
1373
|
-
// - You are a helpful and professional technical assistant named ${object_unit} builder.
|
|
1374
|
-
|
|
1375
|
-
// ### Tasks ###
|
|
1376
|
-
|
|
1377
|
-
// Your job is to assist the user with creating a ${user_prompt} that includes modern ui using Tailwind
|
|
1378
|
-
|
|
1379
|
-
// - You must include all relevant fields a typical ${user_prompt} would require
|
|
1380
|
-
|
|
1381
|
-
// - Follow the format and conventions shown in the ${object_unit} structure example.
|
|
1382
|
-
// - use uid for "createdByUid" and "checkedInUserId"
|
|
1383
|
-
|
|
1384
|
-
// ### workflow ###
|
|
1385
|
-
|
|
1386
|
-
// Steps:
|
|
1387
|
-
// 1. Use create_initial_studio_doc_tool to create the initial doc assign the return result in "doc" variable.
|
|
1388
|
-
|
|
1389
|
-
// 2. use ### Structure and Examples ### section to build the object
|
|
1390
|
-
// 3. Use check_studio_doc_tool to check the ${object_unit} send the ${object_unit} as the doc, fix the issues if needed. if the check fail for 10 times the throw error, skip **Save Doc** tool if errors exist
|
|
1391
|
-
// 4. Use **Save Doc** tool to save the ${object_unit} doc and update the result in save_result variable,NEVER save if errors exist after check_studio_doc_tool
|
|
1392
|
-
|
|
1393
|
-
// ### Additional information ###
|
|
1394
|
-
// ${studio_units[object_unit].short}
|
|
1395
|
-
|
|
1396
|
-
// ### Structure and Examples ###
|
|
1397
|
-
|
|
1398
|
-
// ${get_zod_unit_schema('component')}
|
|
1399
|
-
|
|
1400
|
-
// ### Output ###
|
|
1401
|
-
// if success: {code:1,data:save_result}
|
|
1402
|
-
// if fail: {code:-1,data:error}
|
|
1403
|
-
// `;
|
|
1404
|
-
// };
|
|
1405
|
-
// const get_get_data_instructions = function (object_unit) {
|
|
1406
|
-
// return `
|
|
1407
|
-
// ### context ###
|
|
1408
|
-
// uid=${uid}
|
|
1409
|
-
// app_id=${app_id}
|
|
1410
|
-
|
|
1411
|
-
// ### Persona & Role ###
|
|
1412
|
-
// - You are a helpful and professional technical assistant named ${object_unit} builder.
|
|
1413
|
-
|
|
1414
|
-
// ### Tasks ###
|
|
1415
|
-
|
|
1416
|
-
// Your job is to assist the user with creating a ${user_prompt}.
|
|
1417
|
-
|
|
1418
|
-
// - You must include all relevant fields a typical ${user_prompt} would require
|
|
1419
|
-
|
|
1420
|
-
// - Follow the format and conventions shown in the ${object_unit} structure example.
|
|
1421
|
-
// - use uid for "createdByUid" and "checkedInUserId"
|
|
1422
|
-
|
|
1423
|
-
// ### workflow ###
|
|
1424
|
-
|
|
1425
|
-
// Steps:
|
|
1426
|
-
// 1. Use create_initial_studio_doc_tool to create the initial doc assign the return result in "doc" variable.
|
|
1427
|
-
// 2. Get the ${object_unit} structure example from ### Structure and Examples ### section.
|
|
1428
|
-
// 3. Build the ${object_unit} and validate against vs_68af4c84631c81919709268c2d0f1687
|
|
1429
|
-
// 4. Use check_studio_doc_tool to check the ${object_unit} send the ${object_unit} as the doc, fix the issues if needed. if the check fail for 10 times the throw error, skip **Save Doc** tool if errors exist
|
|
1430
|
-
// 5. Use **Save Doc** tool to save the ${object_unit} doc and update the result in save_result variable,NEVER save if errors exist after check_studio_doc_tool
|
|
1431
|
-
|
|
1432
|
-
// ### Additional information ###
|
|
1433
|
-
// ${studio_units[object_unit].short}
|
|
1434
|
-
|
|
1435
|
-
// ### Output ###
|
|
1436
|
-
// if success: {code:1,data:save_result}
|
|
1437
|
-
// if fail: {code:-1,data:error}
|
|
1438
|
-
// `;
|
|
1439
|
-
// };
|
|
1440
|
-
|
|
1441
|
-
// const get_agents_as_a_tool = function (agent_list = []) {
|
|
1442
|
-
// let _tools = [];
|
|
1443
|
-
// for (const agent of agent_list) {
|
|
1444
|
-
// const _agent = new Agent(studio_agents_obj[agent]);
|
|
1445
|
-
// const tool = _agent.asTool({
|
|
1446
|
-
// toolName: studio_agents_obj[agent].name,
|
|
1447
|
-
// toolDescription: `Generate a ${agent} of the supplied text.`,
|
|
1448
|
-
// });
|
|
1449
|
-
|
|
1450
|
-
// _tools.push(tool);
|
|
1451
|
-
// }
|
|
1452
|
-
|
|
1453
|
-
// return _tools;
|
|
1454
|
-
// };
|
|
1455
|
-
|
|
1456
|
-
// let studio_agents_obj = {
|
|
1457
|
-
// app: {
|
|
1458
|
-
// name: 'App builder',
|
|
1459
|
-
// instructions: get_app_instructions(),
|
|
1460
|
-
// tools: [get_user_name_tool],
|
|
1461
|
-
// model,
|
|
1462
|
-
// modelSettings: {
|
|
1463
|
-
// toolChoice: 'required', // ← this enables tool use
|
|
1464
|
-
// responseFormat: {
|
|
1465
|
-
// text: {
|
|
1466
|
-
// format: {
|
|
1467
|
-
// type: 'array', // or "markdown" if needed
|
|
1468
|
-
// },
|
|
1469
|
-
// },
|
|
1470
|
-
// },
|
|
1471
|
-
// outputType: z.array(z.object()),
|
|
1472
|
-
// },
|
|
1473
|
-
// },
|
|
1474
|
-
// table: {
|
|
1475
|
-
// name: 'Table builder',
|
|
1476
|
-
// instructions: get_table_instructions('table'),
|
|
1477
|
-
// tools: [get_user_name_tool, create_initial_studio_doc_tool, check_studio_doc_tool, save_doc_tool], //fileSearchTool('vs_68af4c84631c81919709268c2d0f1687'), fileSearchTool('vs_68af473196a88191afc6610fddfe4a62')
|
|
1478
|
-
// model,
|
|
1479
|
-
// modelSettings: {
|
|
1480
|
-
// toolChoice: 'required', // ← this enables tool use
|
|
1481
|
-
// responseFormat: {
|
|
1482
|
-
// text: {
|
|
1483
|
-
// format: {
|
|
1484
|
-
// type: 'array', // or "markdown" if needed
|
|
1485
|
-
// },
|
|
1486
|
-
// },
|
|
1487
|
-
// },
|
|
1488
|
-
// outputType: z.array(
|
|
1489
|
-
// z.object({
|
|
1490
|
-
// _id: z.string(),
|
|
1491
|
-
// stat: z.number(),
|
|
1492
|
-
// docType: z.string(),
|
|
1493
|
-
// docDate: z.number(),
|
|
1494
|
-
// ts: z.number(),
|
|
1495
|
-
// order_ts: z.number(),
|
|
1496
|
-
// studio_meta: z.object({
|
|
1497
|
-
// created: z.number(),
|
|
1498
|
-
// createdByUid: z.string(),
|
|
1499
|
-
// checkedInUserId: z.string(),
|
|
1500
|
-
// savedByUid: z.string(),
|
|
1501
|
-
// checkedInUserName: z.string(),
|
|
1502
|
-
// parentId: z.string(),
|
|
1503
|
-
// source: z.string(),
|
|
1504
|
-
// }),
|
|
1505
|
-
// properties: z.object({
|
|
1506
|
-
// menuName: z.string(),
|
|
1507
|
-
// menuType: z.string(),
|
|
1508
|
-
// databaseSocket: z.string(),
|
|
1509
|
-
// }),
|
|
1510
|
-
// tableIndexes: z.array(
|
|
1511
|
-
// z.object({
|
|
1512
|
-
// id: z.string(),
|
|
1513
|
-
// data: z.object({
|
|
1514
|
-
// name: z.string(),
|
|
1515
|
-
// unique: z.boolean(),
|
|
1516
|
-
// keys: z.array(z.string()),
|
|
1517
|
-
// }),
|
|
1518
|
-
// props: z.object({}),
|
|
1519
|
-
// }),
|
|
1520
|
-
// ),
|
|
1521
|
-
// tableFields: z.array(
|
|
1522
|
-
// z.object({
|
|
1523
|
-
// id: z.string(),
|
|
1524
|
-
// data: z.object({
|
|
1525
|
-
// field_id: z.string(),
|
|
1526
|
-
// }),
|
|
1527
|
-
// props: z.object({
|
|
1528
|
-
// label: z.string(),
|
|
1529
|
-
// fieldType: z.string(),
|
|
1530
|
-
// }),
|
|
1531
|
-
// }),
|
|
1532
|
-
// ),
|
|
1533
|
-
// }),
|
|
1534
|
-
// ),
|
|
1535
|
-
// },
|
|
1536
|
-
// },
|
|
1537
|
-
// folder: {
|
|
1538
|
-
// name: 'Folder builder',
|
|
1539
|
-
// instructions: get_folder_instructions('folder'),
|
|
1540
|
-
// tools: [get_user_name_tool, create_initial_studio_doc_tool, check_studio_doc_tool, save_doc_tool], //fileSearchTool('vs_68af4c84631c81919709268c2d0f1687'), fileSearchTool('vs_68af44989e4881918fc8bf8e84c6ce03')
|
|
1541
|
-
// model, //: 'gpt-4o'
|
|
1542
|
-
// modelSettings: {
|
|
1543
|
-
// toolChoice: 'required', // ← this enables tool use
|
|
1544
|
-
// responseFormat: {
|
|
1545
|
-
// text: {
|
|
1546
|
-
// format: {
|
|
1547
|
-
// type: 'array', // or "markdown" if needed
|
|
1548
|
-
// },
|
|
1549
|
-
// },
|
|
1550
|
-
// },
|
|
1551
|
-
// outputType: z.array(
|
|
1552
|
-
// z.object({
|
|
1553
|
-
// _id: z.string(),
|
|
1554
|
-
// stat: z.number(),
|
|
1555
|
-
// docType: z.string(),
|
|
1556
|
-
// docDate: z.number(),
|
|
1557
|
-
// ts: z.number(),
|
|
1558
|
-
// order_ts: z.number(),
|
|
1559
|
-
// studio_meta: z.object({
|
|
1560
|
-
// created: z.number(),
|
|
1561
|
-
// createdByUid: z.string(),
|
|
1562
|
-
// checkedInUserId: z.string(),
|
|
1563
|
-
// savedByUid: z.string(),
|
|
1564
|
-
// checkedInUserName: z.string(),
|
|
1565
|
-
// parentId: z.string(),
|
|
1566
|
-
// source: z.string(),
|
|
1567
|
-
// }),
|
|
1568
|
-
// properties: z.object({
|
|
1569
|
-
// menuName: z.string(),
|
|
1570
|
-
// menuType: z.string(),
|
|
1571
|
-
// databaseSocket: z.string(),
|
|
1572
|
-
// }),
|
|
1573
|
-
// }),
|
|
1574
|
-
// ),
|
|
1575
|
-
// },
|
|
1576
|
-
// },
|
|
1577
|
-
// component: {
|
|
1578
|
-
// name: 'Component builder',
|
|
1579
|
-
// instructions: get_component_instructions('component'),
|
|
1580
|
-
// tools: [get_user_name_tool, create_initial_studio_doc_tool, check_studio_doc_tool, save_doc_tool], //, fileSearchTool('vs_68af48a65cf88191a48a0f530d7e3919')
|
|
1581
|
-
// model,
|
|
1582
|
-
// modelSettings: {
|
|
1583
|
-
// toolChoice: 'required', // ← this enables tool use
|
|
1584
|
-
// responseFormat: {
|
|
1585
|
-
// text: {
|
|
1586
|
-
// format: {
|
|
1587
|
-
// type: 'array', // or "markdown" if needed
|
|
1588
|
-
// },
|
|
1589
|
-
// },
|
|
1590
|
-
// },
|
|
1591
|
-
// outputType: z.array(
|
|
1592
|
-
// z.object({
|
|
1593
|
-
// _id: z.string(),
|
|
1594
|
-
// stat: z.number(),
|
|
1595
|
-
// docType: z.string(),
|
|
1596
|
-
// docDate: z.number(),
|
|
1597
|
-
// ts: z.number(),
|
|
1598
|
-
// order_ts: z.number(),
|
|
1599
|
-
// studio_meta: z.object({
|
|
1600
|
-
// created: z.number(),
|
|
1601
|
-
// createdByUid: z.string(),
|
|
1602
|
-
// checkedInUserId: z.string(),
|
|
1603
|
-
// savedByUid: z.string(),
|
|
1604
|
-
// checkedInUserName: z.string(),
|
|
1605
|
-
// parentId: z.string(),
|
|
1606
|
-
// source: z.string(),
|
|
1607
|
-
// }),
|
|
1608
|
-
// properties: z.object({
|
|
1609
|
-
// menuName: z.string(),
|
|
1610
|
-
// menuType: z.string(),
|
|
1611
|
-
// databaseSocket: z.string(),
|
|
1612
|
-
// }),
|
|
1613
|
-
// progDataSource: z.object({}),
|
|
1614
|
-
// progFields: z.array(z.object({})),
|
|
1615
|
-
// progEvents: z.array(z.object({})),
|
|
1616
|
-
// progUi: z.array(z.object({})),
|
|
1617
|
-
// }),
|
|
1618
|
-
// ),
|
|
1619
|
-
// },
|
|
1620
|
-
// },
|
|
1621
|
-
// get_data: {
|
|
1622
|
-
// name: 'Get data builder',
|
|
1623
|
-
// instructions: get_get_data_instructions('get_data'),
|
|
1624
|
-
// tools: [get_user_name_tool, create_initial_studio_doc_tool, check_studio_doc_tool, save_doc_tool], //fileSearchTool('vs_68af4c84631c81919709268c2d0f1687'), fileSearchTool('vs_68af530d4ba081919ca57eabb5ae117a')
|
|
1625
|
-
// model,
|
|
1626
|
-
// modelSettings: {
|
|
1627
|
-
// toolChoice: 'required', // ← this enables tool use
|
|
1628
|
-
// responseFormat: {
|
|
1629
|
-
// text: {
|
|
1630
|
-
// format: {
|
|
1631
|
-
// type: 'array', // or "markdown" if needed
|
|
1632
|
-
// },
|
|
1633
|
-
// },
|
|
1634
|
-
// },
|
|
1635
|
-
// outputType: z.array(
|
|
1636
|
-
// z.object({
|
|
1637
|
-
// _id: z.string(),
|
|
1638
|
-
// stat: z.number(),
|
|
1639
|
-
// docType: z.string(),
|
|
1640
|
-
// docDate: z.number(),
|
|
1641
|
-
// ts: z.number(),
|
|
1642
|
-
// order_ts: z.number(),
|
|
1643
|
-
// studio_meta: z.object({
|
|
1644
|
-
// created: z.number(),
|
|
1645
|
-
// createdByUid: z.string(),
|
|
1646
|
-
// checkedInUserId: z.string(),
|
|
1647
|
-
// savedByUid: z.string(),
|
|
1648
|
-
// checkedInUserName: z.string(),
|
|
1649
|
-
// parentId: z.string(),
|
|
1650
|
-
// source: z.string(),
|
|
1651
|
-
// }),
|
|
1652
|
-
// properties: z.object({
|
|
1653
|
-
// menuName: z.string(),
|
|
1654
|
-
// menuType: z.string(),
|
|
1655
|
-
// databaseSocket: z.string(),
|
|
1656
|
-
// }),
|
|
1657
|
-
// progDataSource: z.object({}),
|
|
1658
|
-
// progFields: z.array(z.object({})),
|
|
1659
|
-
// progEvents: z.array(z.object({})),
|
|
1660
|
-
// }),
|
|
1661
|
-
// ),
|
|
1662
|
-
// },
|
|
1663
|
-
// },
|
|
1664
|
-
// };
|
|
1665
|
-
|
|
1666
|
-
// if (object_unit === 'app') {
|
|
1667
|
-
// const agents_as_a_tool_arr = get_agents_as_a_tool(['table', 'folder', 'component', 'get_data']);
|
|
1668
|
-
// studio_agents_obj.app.tools = [...studio_agents_obj.app.tools, ...agents_as_a_tool_arr];
|
|
1669
|
-
// }
|
|
1670
|
-
|
|
1671
|
-
// const run = async function (user_prompt, object_unit) {
|
|
1672
|
-
// const _agent = new Agent(studio_agents_obj[object_unit]);
|
|
1673
|
-
// const runner = new Runner();
|
|
1674
|
-
|
|
1675
|
-
// const result = await runner.run(_agent, user_prompt, {
|
|
1676
|
-
// context: { uid, app_id, userName },
|
|
1677
|
-
// });
|
|
1678
|
-
|
|
1679
|
-
// return result;
|
|
1680
|
-
// };
|
|
1681
|
-
|
|
1682
|
-
// const result = await run(user_prompt, object_unit);
|
|
1683
|
-
|
|
1684
|
-
// return { code: 100, data: result.finalOutput };
|
|
1685
|
-
// } catch (err) {
|
|
1686
|
-
// debugger;
|
|
1687
|
-
// console.error('>>>>> AI:', err);
|
|
1688
|
-
// console.error('Cause:', err?.cause?.message);
|
|
1689
|
-
// return { code: -100, data: err.message };
|
|
1690
|
-
// }
|
|
1691
|
-
// };
|
|
1692
|
-
|
|
1693
|
-
// export const get_chat_conversation = async function (req) {
|
|
1694
|
-
// let { conversation_id, order = 'asc', limit, after, _id, uid } = req;
|
|
1695
|
-
|
|
1696
|
-
// const account_profile_info = await account_module.get_active_account_profile_info(uid);
|
|
1697
|
-
|
|
1698
|
-
// if (_id) {
|
|
1699
|
-
|
|
1700
|
-
// let data = await db_module.get_app_couch_doc(account_profile_info.app_id, _id);
|
|
1701
|
-
// return data;
|
|
1702
|
-
// }
|
|
1703
|
-
|
|
1704
|
-
// try {
|
|
1705
|
-
// // const project_db = await get_account_project_db(uid);
|
|
1706
|
-
// // let conversation_doc = await project_db.get(conversation_id);
|
|
1707
|
-
// let conversation_doc = await db_module.get_app_couch_doc(account_profile_info.app_id, conversation_id);
|
|
1708
|
-
// let reference_doc;
|
|
1709
|
-
// if (conversation_doc.shared_from_uid) {
|
|
1710
|
-
// reference_doc = _.cloneDeep(conversation_doc);
|
|
1711
|
-
// conversation_doc = await db_module.get_app_couch_doc_native(reference_doc.shared_from_app_id, reference_doc.share_item_id);
|
|
1712
|
-
// conversation_doc.reference_doc = reference_doc;
|
|
1713
|
-
// }
|
|
1714
|
-
// let conversation = await client.conversations.items.list(conversation_id, { limit, order, after });
|
|
1715
|
-
|
|
1716
|
-
// return { code: 15, data: { conversation, ...conversation_doc } };
|
|
1717
|
-
// } catch (err) {
|
|
1718
|
-
// return { code: -15, data: err.message };
|
|
1719
|
-
// }
|
|
1720
|
-
// };
|
|
1721
|
-
|
|
1722
1072
|
export const get_chat_conversation = async function (req) {
|
|
1723
1073
|
let { conversation_id, order = 'asc', limit = 9999, skip = 0, _id, uid } = req;
|
|
1724
1074
|
|
package/old.mjs
CHANGED
|
@@ -4788,3 +4788,658 @@ for await (let account_profile of profile_requests_from_res.docs) {
|
|
|
4788
4788
|
|
|
4789
4789
|
// return normalizedBuffer.toString('base64'); // Return normalized base64 string
|
|
4790
4790
|
// }
|
|
4791
|
+
|
|
4792
|
+
|
|
4793
|
+
/////////////////////
|
|
4794
|
+
|
|
4795
|
+
|
|
4796
|
+
|
|
4797
|
+
// export const submit_agentic_studio_chat_gpt_prompt = async function (req) {
|
|
4798
|
+
// try {
|
|
4799
|
+
// const { user_prompt, object_unit = 'app', uid, app_id } = req;
|
|
4800
|
+
// // const model = 'ft:gpt-4o-2024-08-06:xuda-io:vps-hosting-plans:CDaxQiXo'; // 'gpt-4o'; //'gpt-4.1'; //
|
|
4801
|
+
|
|
4802
|
+
// const app_obj = await get_app_obj(app_id);
|
|
4803
|
+
|
|
4804
|
+
// // let check_results = {};
|
|
4805
|
+
// const auth = async function () {
|
|
4806
|
+
// if (app_obj.app_uId !== uid) {
|
|
4807
|
+
// const db_team = get_xuda_couch('xuda_team');
|
|
4808
|
+
// let master_auth_users = await db_team.view('xuda', 'user_active_shares', {
|
|
4809
|
+
// key: [uid, app_id],
|
|
4810
|
+
// });
|
|
4811
|
+
// if (!master_auth_users.rows.includes(uid)) {
|
|
4812
|
+
// throw new Error('user unauthorized');
|
|
4813
|
+
// }
|
|
4814
|
+
// }
|
|
4815
|
+
// };
|
|
4816
|
+
|
|
4817
|
+
// await auth();
|
|
4818
|
+
|
|
4819
|
+
// const userName = await get_user_name(uid);
|
|
4820
|
+
|
|
4821
|
+
// const get_zod_unit_schema = function (type) {
|
|
4822
|
+
// init(app_obj, {}, _, true, null, null, UglifyJS, JSON5, _conf, false, z);
|
|
4823
|
+
// const schema = get_zod_schema(type);
|
|
4824
|
+
// const jsonSchema = zodToJsonSchema(schema);
|
|
4825
|
+
// return JSON.stringify(jsonSchema, null, 2);
|
|
4826
|
+
// };
|
|
4827
|
+
|
|
4828
|
+
// const get_app_instructions = function (object_unit) {
|
|
4829
|
+
// return `
|
|
4830
|
+
// ### context ###
|
|
4831
|
+
// uid=${uid}
|
|
4832
|
+
// app_id=${app_id}
|
|
4833
|
+
|
|
4834
|
+
// ### Persona & Role ###
|
|
4835
|
+
// - You are a helpful and professional technical assistant named ${object_unit} builder.
|
|
4836
|
+
|
|
4837
|
+
// ### Tasks ###
|
|
4838
|
+
|
|
4839
|
+
// Your job is to assist the user with creating a ${user_prompt} that includes all tasks needed.
|
|
4840
|
+
|
|
4841
|
+
// ### workflow ###
|
|
4842
|
+
|
|
4843
|
+
// Steps:
|
|
4844
|
+
// 1. list all the tables needed for the task.
|
|
4845
|
+
// 2. prefix each table with the subject of the ${user_prompt} (e.g: CRM - Tasks).
|
|
4846
|
+
// 3. iterate the table list and build tables array using the Table builder tool, add the Table builder tool results and the table name in array RESULTS_ARR.
|
|
4847
|
+
|
|
4848
|
+
// ### Additional information ###
|
|
4849
|
+
|
|
4850
|
+
// ### Output ###
|
|
4851
|
+
// return the RESULTS_ARR Array.
|
|
4852
|
+
|
|
4853
|
+
// ### Examples ###
|
|
4854
|
+
|
|
4855
|
+
// `;
|
|
4856
|
+
// };
|
|
4857
|
+
|
|
4858
|
+
// const get_table_instructions = function (object_unit) {
|
|
4859
|
+
// return `
|
|
4860
|
+
// ### context ###
|
|
4861
|
+
// uid=${uid}
|
|
4862
|
+
// app_id=${app_id}
|
|
4863
|
+
|
|
4864
|
+
// ### Persona & Role ###
|
|
4865
|
+
// - You are a helpful and professional technical assistant named ${object_unit} builder.
|
|
4866
|
+
|
|
4867
|
+
// ### Tasks ###
|
|
4868
|
+
|
|
4869
|
+
// Your job is to assist the user with creating a ${user_prompt} that includes a full set of fields according to the provided ${object_unit} structure.
|
|
4870
|
+
|
|
4871
|
+
// - You must include all relevant fields a typical ${user_prompt} would require
|
|
4872
|
+
// - Add **multiple entries** in the "tableFields" array as needed to fully represent the structure.
|
|
4873
|
+
// - Follow the format and conventions shown in the ${object_unit} structure example.
|
|
4874
|
+
// - use uid for "createdByUid" and "checkedInUserId"
|
|
4875
|
+
|
|
4876
|
+
// ### workflow ###
|
|
4877
|
+
|
|
4878
|
+
// Steps:
|
|
4879
|
+
// 1. Use create_initial_studio_doc_tool to create the initial doc assign the return result in "doc" variable.
|
|
4880
|
+
|
|
4881
|
+
// 3. Use check_studio_doc_tool to check the ${object_unit} send the ${object_unit} as the doc, fix the issues if needed. if the check fail for 3 times the throw error, skip **Save Doc** tool if errors exist
|
|
4882
|
+
// 4. Use **Save Doc** tool to save the ${object_unit} doc and update the result in save_result variable,NEVER save if errors exist after check_studio_doc_tool
|
|
4883
|
+
|
|
4884
|
+
// ### Output ###
|
|
4885
|
+
// if success: {code:1,data:save_result}
|
|
4886
|
+
// if fail: {code:-1,data:error}
|
|
4887
|
+
|
|
4888
|
+
// ### EXAMPLE
|
|
4889
|
+
|
|
4890
|
+
// {
|
|
4891
|
+
// "_id": "5b1_tbl_47f0ac6059ca",
|
|
4892
|
+
// "app_id": "prj3937cb6f9a31c8c7dea25055bba845b1",
|
|
4893
|
+
// "stat": 3,
|
|
4894
|
+
// "docType": "studio",
|
|
4895
|
+
// "docDate": 1714916369797,
|
|
4896
|
+
// "ts": 1762953659001,
|
|
4897
|
+
// "order_ts": 1714916369797,
|
|
4898
|
+
// "studio_meta": {
|
|
4899
|
+
// "created": 1714916369797,
|
|
4900
|
+
// "createdByUid": "341cf2d32991a68e4d8aaba6c16e15cc",
|
|
4901
|
+
// "checkedInUserId": "341cf2d32991a68e4d8aaba6c16e15cc",
|
|
4902
|
+
// "checkedInUserName": "Ioshka Media",
|
|
4903
|
+
// "parentId": "database",
|
|
4904
|
+
// "savedByUid": "341cf2d32991a68e4d8aaba6c16e15cc"
|
|
4905
|
+
// },
|
|
4906
|
+
// "properties": {
|
|
4907
|
+
// "menuType": "table",
|
|
4908
|
+
// "menuName": "PT - Practice Table",
|
|
4909
|
+
// "databaseSocket": "@xuda.io/xuda-dbs-plugin-xuda",
|
|
4910
|
+
// "menuTitle": "PT - Practice Table"
|
|
4911
|
+
// },
|
|
4912
|
+
// "tableIndexes": [
|
|
4913
|
+
// {
|
|
4914
|
+
// "id": "76bbf201-997e-402c-b435-0649cc25d117",
|
|
4915
|
+
// "data": {
|
|
4916
|
+
// "name": "Primary_Index",
|
|
4917
|
+
// "unique": true,
|
|
4918
|
+
// "keys": [
|
|
4919
|
+
// "PT_Id"
|
|
4920
|
+
// ]
|
|
4921
|
+
// },
|
|
4922
|
+
// "props": {} <-- must appear even if empty
|
|
4923
|
+
// },
|
|
4924
|
+
// {
|
|
4925
|
+
// "id": "89f1609d-de4e-4b61-9357-284b1261314c",
|
|
4926
|
+
// "data": {
|
|
4927
|
+
// "name": "Index_2",
|
|
4928
|
+
// "unique": false,
|
|
4929
|
+
// "keys": [
|
|
4930
|
+
// "PT_Stat",
|
|
4931
|
+
// "PT_Group_Id"
|
|
4932
|
+
// ]
|
|
4933
|
+
// },
|
|
4934
|
+
// "props": {} <-- must appear even if empty
|
|
4935
|
+
// }
|
|
4936
|
+
// ],
|
|
4937
|
+
// "tableFields": [
|
|
4938
|
+
// {
|
|
4939
|
+
// "id": "b41aa880-56ec-4029-a21b-60c89a52b62e",
|
|
4940
|
+
// "data": {
|
|
4941
|
+
// "field_id": "PT_Id"
|
|
4942
|
+
// },
|
|
4943
|
+
// "props": {
|
|
4944
|
+
// "label":"Practice Id",
|
|
4945
|
+
// "fieldType": "string",
|
|
4946
|
+
// "mandatory": true
|
|
4947
|
+
// }
|
|
4948
|
+
|
|
4949
|
+
// },
|
|
4950
|
+
// {
|
|
4951
|
+
// "id": "8aec82db-35d9-4828-9fc7-49373c531cc3",
|
|
4952
|
+
// "data": {
|
|
4953
|
+
// "field_id": "PT_Type"
|
|
4954
|
+
// },
|
|
4955
|
+
// "props": {
|
|
4956
|
+
// "label":"Practice Type",
|
|
4957
|
+
// "fieldType": "string",
|
|
4958
|
+
// "mandatory": true
|
|
4959
|
+
// }
|
|
4960
|
+
|
|
4961
|
+
// },
|
|
4962
|
+
// {
|
|
4963
|
+
// "id": "d27c56e5-faec-4a0a-ad42-7bf55f8c67b3",
|
|
4964
|
+
// "data": {
|
|
4965
|
+
// "field_id": "PT_Stat"
|
|
4966
|
+
// },
|
|
4967
|
+
// "props": {
|
|
4968
|
+
// "label":"Practice Status",
|
|
4969
|
+
// "fieldType": "number",
|
|
4970
|
+
// "fieldComment": "1 = Draft\n2 = Private\n3 = Public\n4 = Deleted",
|
|
4971
|
+
// "mandatory": true
|
|
4972
|
+
// }
|
|
4973
|
+
|
|
4974
|
+
// },
|
|
4975
|
+
// {
|
|
4976
|
+
// "id": "659fbfb3-7dcc-4ea0-b1e9-5dd9553a99fc",
|
|
4977
|
+
// "data": {
|
|
4978
|
+
// "field_id": "PT_Question"
|
|
4979
|
+
// },
|
|
4980
|
+
// "props": {
|
|
4981
|
+
// "label":"Practice Question",
|
|
4982
|
+
// "fieldType": "string"
|
|
4983
|
+
// }
|
|
4984
|
+
|
|
4985
|
+
// },
|
|
4986
|
+
// {
|
|
4987
|
+
// "id": "080c8ceb-5a51-437b-8ad1-9fc005c79011",
|
|
4988
|
+
// "data": {
|
|
4989
|
+
// "field_id": "PT_Options"
|
|
4990
|
+
// },
|
|
4991
|
+
// "props": {
|
|
4992
|
+
// "label":"Practice Options",
|
|
4993
|
+
// "fieldType": "array"
|
|
4994
|
+
// }
|
|
4995
|
+
|
|
4996
|
+
// },
|
|
4997
|
+
// {
|
|
4998
|
+
// "id": "72c04aac-b3e7-4e7a-8a74-31075de3dbec",
|
|
4999
|
+
// "data": {
|
|
5000
|
+
// "field_id": "PT_Answer"
|
|
5001
|
+
// },
|
|
5002
|
+
// "props": {
|
|
5003
|
+
// "label":"Practice Answer",
|
|
5004
|
+
// "fieldType": "string"
|
|
5005
|
+
// }
|
|
5006
|
+
|
|
5007
|
+
// },
|
|
5008
|
+
// {
|
|
5009
|
+
// "id": "e37b08c6-f340-425a-bf01-809b28a486d3",
|
|
5010
|
+
// "data": {
|
|
5011
|
+
// "field_id": "PT_Matching_Answer"
|
|
5012
|
+
// },
|
|
5013
|
+
// "props": {
|
|
5014
|
+
// "label":"Practice Matching Answer",
|
|
5015
|
+
// "fieldType": "object"
|
|
5016
|
+
// },
|
|
5017
|
+
|
|
5018
|
+
// },
|
|
5019
|
+
// {
|
|
5020
|
+
// "id": "8ca4ace1-2010-45be-b7aa-2672ce0e6fea",
|
|
5021
|
+
// "data": {
|
|
5022
|
+
// "field_id": "PT_Group_Id"
|
|
5023
|
+
// },
|
|
5024
|
+
// "props": {
|
|
5025
|
+
// "label":"Practice Group Id",
|
|
5026
|
+
// "fieldType": "string"
|
|
5027
|
+
// }
|
|
5028
|
+
|
|
5029
|
+
// },
|
|
5030
|
+
// {
|
|
5031
|
+
// "id": "ae749c6d-1f39-4750-b79e-f016d50b8a11",
|
|
5032
|
+
// "data": {
|
|
5033
|
+
// "field_id": "PT_Difficulty"
|
|
5034
|
+
// },
|
|
5035
|
+
// "props": {
|
|
5036
|
+
// "label":"Practice Difficulty",
|
|
5037
|
+
// "fieldType": "number"
|
|
5038
|
+
// },
|
|
5039
|
+
|
|
5040
|
+
// },
|
|
5041
|
+
// {
|
|
5042
|
+
// "id": "5c5e7cb5-feee-4bc7-9d94-0ccd04a5eb06",
|
|
5043
|
+
// "data": {
|
|
5044
|
+
// "field_id": "PT_Uid"
|
|
5045
|
+
// },
|
|
5046
|
+
// "props": {
|
|
5047
|
+
// "label":"Practice User Id",
|
|
5048
|
+
// "fieldType": "string"
|
|
5049
|
+
// }
|
|
5050
|
+
|
|
5051
|
+
// }
|
|
5052
|
+
// ]
|
|
5053
|
+
// }
|
|
5054
|
+
// `;
|
|
5055
|
+
// };
|
|
5056
|
+
|
|
5057
|
+
// const get_folder_instructions = function (object_unit) {
|
|
5058
|
+
// return `
|
|
5059
|
+
// ### context ###
|
|
5060
|
+
// uid=${uid}
|
|
5061
|
+
// app_id=${app_id}
|
|
5062
|
+
|
|
5063
|
+
// ### Persona & Role ###
|
|
5064
|
+
// - You are a helpful and professional technical assistant named ${object_unit} builder.
|
|
5065
|
+
|
|
5066
|
+
// ### Tasks ###
|
|
5067
|
+
|
|
5068
|
+
// Your job is to assist the user with creating a ${user_prompt}.
|
|
5069
|
+
|
|
5070
|
+
// - Follow the format and conventions shown in the ${object_unit} structure example.
|
|
5071
|
+
// - use uid for "createdByUid" and "checkedInUserId"
|
|
5072
|
+
|
|
5073
|
+
// ### workflow ###
|
|
5074
|
+
|
|
5075
|
+
// Steps:
|
|
5076
|
+
// 1. Use create_initial_studio_doc_tool to create the initial doc assign the return result in "doc" variable.
|
|
5077
|
+
// 2. Get the ${object_unit} structure example from ### Structure and Examples ### section.
|
|
5078
|
+
// 3. Build the ${object_unit} and validate against vs_68af4c84631c81919709268c2d0f1687
|
|
5079
|
+
// 4. Use check_studio_doc_tool to check the ${object_unit} send the ${object_unit} as the doc, fix the issues if needed. if the check fail for 3 times the throw error, skip **Save Doc** tool if errors exist
|
|
5080
|
+
// 5. Use **Save Doc** tool to save the ${object_unit} doc and update the result in save_result variable,NEVER save if errors exist after check_studio_doc_tool
|
|
5081
|
+
|
|
5082
|
+
// ### Additional information ###
|
|
5083
|
+
// ${studio_units[object_unit].short}
|
|
5084
|
+
|
|
5085
|
+
// ### Output ###
|
|
5086
|
+
// if success: {code:1,data:save_result}
|
|
5087
|
+
// if fail: {code:-1,data:error}
|
|
5088
|
+
// `;
|
|
5089
|
+
// };
|
|
5090
|
+
|
|
5091
|
+
// const get_component_instructions = function (object_unit) {
|
|
5092
|
+
// return `
|
|
5093
|
+
// ### context ###
|
|
5094
|
+
// uid=${uid}
|
|
5095
|
+
// app_id=${app_id}
|
|
5096
|
+
|
|
5097
|
+
// ### Persona & Role ###
|
|
5098
|
+
// - You are a helpful and professional technical assistant named ${object_unit} builder.
|
|
5099
|
+
|
|
5100
|
+
// ### Tasks ###
|
|
5101
|
+
|
|
5102
|
+
// Your job is to assist the user with creating a ${user_prompt} that includes modern ui using Tailwind
|
|
5103
|
+
|
|
5104
|
+
// - You must include all relevant fields a typical ${user_prompt} would require
|
|
5105
|
+
|
|
5106
|
+
// - Follow the format and conventions shown in the ${object_unit} structure example.
|
|
5107
|
+
// - use uid for "createdByUid" and "checkedInUserId"
|
|
5108
|
+
|
|
5109
|
+
// ### workflow ###
|
|
5110
|
+
|
|
5111
|
+
// Steps:
|
|
5112
|
+
// 1. Use create_initial_studio_doc_tool to create the initial doc assign the return result in "doc" variable.
|
|
5113
|
+
|
|
5114
|
+
// 2. use ### Structure and Examples ### section to build the object
|
|
5115
|
+
// 3. Use check_studio_doc_tool to check the ${object_unit} send the ${object_unit} as the doc, fix the issues if needed. if the check fail for 10 times the throw error, skip **Save Doc** tool if errors exist
|
|
5116
|
+
// 4. Use **Save Doc** tool to save the ${object_unit} doc and update the result in save_result variable,NEVER save if errors exist after check_studio_doc_tool
|
|
5117
|
+
|
|
5118
|
+
// ### Additional information ###
|
|
5119
|
+
// ${studio_units[object_unit].short}
|
|
5120
|
+
|
|
5121
|
+
// ### Structure and Examples ###
|
|
5122
|
+
|
|
5123
|
+
// ${get_zod_unit_schema('component')}
|
|
5124
|
+
|
|
5125
|
+
// ### Output ###
|
|
5126
|
+
// if success: {code:1,data:save_result}
|
|
5127
|
+
// if fail: {code:-1,data:error}
|
|
5128
|
+
// `;
|
|
5129
|
+
// };
|
|
5130
|
+
// const get_get_data_instructions = function (object_unit) {
|
|
5131
|
+
// return `
|
|
5132
|
+
// ### context ###
|
|
5133
|
+
// uid=${uid}
|
|
5134
|
+
// app_id=${app_id}
|
|
5135
|
+
|
|
5136
|
+
// ### Persona & Role ###
|
|
5137
|
+
// - You are a helpful and professional technical assistant named ${object_unit} builder.
|
|
5138
|
+
|
|
5139
|
+
// ### Tasks ###
|
|
5140
|
+
|
|
5141
|
+
// Your job is to assist the user with creating a ${user_prompt}.
|
|
5142
|
+
|
|
5143
|
+
// - You must include all relevant fields a typical ${user_prompt} would require
|
|
5144
|
+
|
|
5145
|
+
// - Follow the format and conventions shown in the ${object_unit} structure example.
|
|
5146
|
+
// - use uid for "createdByUid" and "checkedInUserId"
|
|
5147
|
+
|
|
5148
|
+
// ### workflow ###
|
|
5149
|
+
|
|
5150
|
+
// Steps:
|
|
5151
|
+
// 1. Use create_initial_studio_doc_tool to create the initial doc assign the return result in "doc" variable.
|
|
5152
|
+
// 2. Get the ${object_unit} structure example from ### Structure and Examples ### section.
|
|
5153
|
+
// 3. Build the ${object_unit} and validate against vs_68af4c84631c81919709268c2d0f1687
|
|
5154
|
+
// 4. Use check_studio_doc_tool to check the ${object_unit} send the ${object_unit} as the doc, fix the issues if needed. if the check fail for 10 times the throw error, skip **Save Doc** tool if errors exist
|
|
5155
|
+
// 5. Use **Save Doc** tool to save the ${object_unit} doc and update the result in save_result variable,NEVER save if errors exist after check_studio_doc_tool
|
|
5156
|
+
|
|
5157
|
+
// ### Additional information ###
|
|
5158
|
+
// ${studio_units[object_unit].short}
|
|
5159
|
+
|
|
5160
|
+
// ### Output ###
|
|
5161
|
+
// if success: {code:1,data:save_result}
|
|
5162
|
+
// if fail: {code:-1,data:error}
|
|
5163
|
+
// `;
|
|
5164
|
+
// };
|
|
5165
|
+
|
|
5166
|
+
// const get_agents_as_a_tool = function (agent_list = []) {
|
|
5167
|
+
// let _tools = [];
|
|
5168
|
+
// for (const agent of agent_list) {
|
|
5169
|
+
// const _agent = new Agent(studio_agents_obj[agent]);
|
|
5170
|
+
// const tool = _agent.asTool({
|
|
5171
|
+
// toolName: studio_agents_obj[agent].name,
|
|
5172
|
+
// toolDescription: `Generate a ${agent} of the supplied text.`,
|
|
5173
|
+
// });
|
|
5174
|
+
|
|
5175
|
+
// _tools.push(tool);
|
|
5176
|
+
// }
|
|
5177
|
+
|
|
5178
|
+
// return _tools;
|
|
5179
|
+
// };
|
|
5180
|
+
|
|
5181
|
+
// let studio_agents_obj = {
|
|
5182
|
+
// app: {
|
|
5183
|
+
// name: 'App builder',
|
|
5184
|
+
// instructions: get_app_instructions(),
|
|
5185
|
+
// tools: [get_user_name_tool],
|
|
5186
|
+
// model,
|
|
5187
|
+
// modelSettings: {
|
|
5188
|
+
// toolChoice: 'required', // ← this enables tool use
|
|
5189
|
+
// responseFormat: {
|
|
5190
|
+
// text: {
|
|
5191
|
+
// format: {
|
|
5192
|
+
// type: 'array', // or "markdown" if needed
|
|
5193
|
+
// },
|
|
5194
|
+
// },
|
|
5195
|
+
// },
|
|
5196
|
+
// outputType: z.array(z.object()),
|
|
5197
|
+
// },
|
|
5198
|
+
// },
|
|
5199
|
+
// table: {
|
|
5200
|
+
// name: 'Table builder',
|
|
5201
|
+
// instructions: get_table_instructions('table'),
|
|
5202
|
+
// tools: [get_user_name_tool, create_initial_studio_doc_tool, check_studio_doc_tool, save_doc_tool], //fileSearchTool('vs_68af4c84631c81919709268c2d0f1687'), fileSearchTool('vs_68af473196a88191afc6610fddfe4a62')
|
|
5203
|
+
// model,
|
|
5204
|
+
// modelSettings: {
|
|
5205
|
+
// toolChoice: 'required', // ← this enables tool use
|
|
5206
|
+
// responseFormat: {
|
|
5207
|
+
// text: {
|
|
5208
|
+
// format: {
|
|
5209
|
+
// type: 'array', // or "markdown" if needed
|
|
5210
|
+
// },
|
|
5211
|
+
// },
|
|
5212
|
+
// },
|
|
5213
|
+
// outputType: z.array(
|
|
5214
|
+
// z.object({
|
|
5215
|
+
// _id: z.string(),
|
|
5216
|
+
// stat: z.number(),
|
|
5217
|
+
// docType: z.string(),
|
|
5218
|
+
// docDate: z.number(),
|
|
5219
|
+
// ts: z.number(),
|
|
5220
|
+
// order_ts: z.number(),
|
|
5221
|
+
// studio_meta: z.object({
|
|
5222
|
+
// created: z.number(),
|
|
5223
|
+
// createdByUid: z.string(),
|
|
5224
|
+
// checkedInUserId: z.string(),
|
|
5225
|
+
// savedByUid: z.string(),
|
|
5226
|
+
// checkedInUserName: z.string(),
|
|
5227
|
+
// parentId: z.string(),
|
|
5228
|
+
// source: z.string(),
|
|
5229
|
+
// }),
|
|
5230
|
+
// properties: z.object({
|
|
5231
|
+
// menuName: z.string(),
|
|
5232
|
+
// menuType: z.string(),
|
|
5233
|
+
// databaseSocket: z.string(),
|
|
5234
|
+
// }),
|
|
5235
|
+
// tableIndexes: z.array(
|
|
5236
|
+
// z.object({
|
|
5237
|
+
// id: z.string(),
|
|
5238
|
+
// data: z.object({
|
|
5239
|
+
// name: z.string(),
|
|
5240
|
+
// unique: z.boolean(),
|
|
5241
|
+
// keys: z.array(z.string()),
|
|
5242
|
+
// }),
|
|
5243
|
+
// props: z.object({}),
|
|
5244
|
+
// }),
|
|
5245
|
+
// ),
|
|
5246
|
+
// tableFields: z.array(
|
|
5247
|
+
// z.object({
|
|
5248
|
+
// id: z.string(),
|
|
5249
|
+
// data: z.object({
|
|
5250
|
+
// field_id: z.string(),
|
|
5251
|
+
// }),
|
|
5252
|
+
// props: z.object({
|
|
5253
|
+
// label: z.string(),
|
|
5254
|
+
// fieldType: z.string(),
|
|
5255
|
+
// }),
|
|
5256
|
+
// }),
|
|
5257
|
+
// ),
|
|
5258
|
+
// }),
|
|
5259
|
+
// ),
|
|
5260
|
+
// },
|
|
5261
|
+
// },
|
|
5262
|
+
// folder: {
|
|
5263
|
+
// name: 'Folder builder',
|
|
5264
|
+
// instructions: get_folder_instructions('folder'),
|
|
5265
|
+
// tools: [get_user_name_tool, create_initial_studio_doc_tool, check_studio_doc_tool, save_doc_tool], //fileSearchTool('vs_68af4c84631c81919709268c2d0f1687'), fileSearchTool('vs_68af44989e4881918fc8bf8e84c6ce03')
|
|
5266
|
+
// model, //: 'gpt-4o'
|
|
5267
|
+
// modelSettings: {
|
|
5268
|
+
// toolChoice: 'required', // ← this enables tool use
|
|
5269
|
+
// responseFormat: {
|
|
5270
|
+
// text: {
|
|
5271
|
+
// format: {
|
|
5272
|
+
// type: 'array', // or "markdown" if needed
|
|
5273
|
+
// },
|
|
5274
|
+
// },
|
|
5275
|
+
// },
|
|
5276
|
+
// outputType: z.array(
|
|
5277
|
+
// z.object({
|
|
5278
|
+
// _id: z.string(),
|
|
5279
|
+
// stat: z.number(),
|
|
5280
|
+
// docType: z.string(),
|
|
5281
|
+
// docDate: z.number(),
|
|
5282
|
+
// ts: z.number(),
|
|
5283
|
+
// order_ts: z.number(),
|
|
5284
|
+
// studio_meta: z.object({
|
|
5285
|
+
// created: z.number(),
|
|
5286
|
+
// createdByUid: z.string(),
|
|
5287
|
+
// checkedInUserId: z.string(),
|
|
5288
|
+
// savedByUid: z.string(),
|
|
5289
|
+
// checkedInUserName: z.string(),
|
|
5290
|
+
// parentId: z.string(),
|
|
5291
|
+
// source: z.string(),
|
|
5292
|
+
// }),
|
|
5293
|
+
// properties: z.object({
|
|
5294
|
+
// menuName: z.string(),
|
|
5295
|
+
// menuType: z.string(),
|
|
5296
|
+
// databaseSocket: z.string(),
|
|
5297
|
+
// }),
|
|
5298
|
+
// }),
|
|
5299
|
+
// ),
|
|
5300
|
+
// },
|
|
5301
|
+
// },
|
|
5302
|
+
// component: {
|
|
5303
|
+
// name: 'Component builder',
|
|
5304
|
+
// instructions: get_component_instructions('component'),
|
|
5305
|
+
// tools: [get_user_name_tool, create_initial_studio_doc_tool, check_studio_doc_tool, save_doc_tool], //, fileSearchTool('vs_68af48a65cf88191a48a0f530d7e3919')
|
|
5306
|
+
// model,
|
|
5307
|
+
// modelSettings: {
|
|
5308
|
+
// toolChoice: 'required', // ← this enables tool use
|
|
5309
|
+
// responseFormat: {
|
|
5310
|
+
// text: {
|
|
5311
|
+
// format: {
|
|
5312
|
+
// type: 'array', // or "markdown" if needed
|
|
5313
|
+
// },
|
|
5314
|
+
// },
|
|
5315
|
+
// },
|
|
5316
|
+
// outputType: z.array(
|
|
5317
|
+
// z.object({
|
|
5318
|
+
// _id: z.string(),
|
|
5319
|
+
// stat: z.number(),
|
|
5320
|
+
// docType: z.string(),
|
|
5321
|
+
// docDate: z.number(),
|
|
5322
|
+
// ts: z.number(),
|
|
5323
|
+
// order_ts: z.number(),
|
|
5324
|
+
// studio_meta: z.object({
|
|
5325
|
+
// created: z.number(),
|
|
5326
|
+
// createdByUid: z.string(),
|
|
5327
|
+
// checkedInUserId: z.string(),
|
|
5328
|
+
// savedByUid: z.string(),
|
|
5329
|
+
// checkedInUserName: z.string(),
|
|
5330
|
+
// parentId: z.string(),
|
|
5331
|
+
// source: z.string(),
|
|
5332
|
+
// }),
|
|
5333
|
+
// properties: z.object({
|
|
5334
|
+
// menuName: z.string(),
|
|
5335
|
+
// menuType: z.string(),
|
|
5336
|
+
// databaseSocket: z.string(),
|
|
5337
|
+
// }),
|
|
5338
|
+
// progDataSource: z.object({}),
|
|
5339
|
+
// progFields: z.array(z.object({})),
|
|
5340
|
+
// progEvents: z.array(z.object({})),
|
|
5341
|
+
// progUi: z.array(z.object({})),
|
|
5342
|
+
// }),
|
|
5343
|
+
// ),
|
|
5344
|
+
// },
|
|
5345
|
+
// },
|
|
5346
|
+
// get_data: {
|
|
5347
|
+
// name: 'Get data builder',
|
|
5348
|
+
// instructions: get_get_data_instructions('get_data'),
|
|
5349
|
+
// tools: [get_user_name_tool, create_initial_studio_doc_tool, check_studio_doc_tool, save_doc_tool], //fileSearchTool('vs_68af4c84631c81919709268c2d0f1687'), fileSearchTool('vs_68af530d4ba081919ca57eabb5ae117a')
|
|
5350
|
+
// model,
|
|
5351
|
+
// modelSettings: {
|
|
5352
|
+
// toolChoice: 'required', // ← this enables tool use
|
|
5353
|
+
// responseFormat: {
|
|
5354
|
+
// text: {
|
|
5355
|
+
// format: {
|
|
5356
|
+
// type: 'array', // or "markdown" if needed
|
|
5357
|
+
// },
|
|
5358
|
+
// },
|
|
5359
|
+
// },
|
|
5360
|
+
// outputType: z.array(
|
|
5361
|
+
// z.object({
|
|
5362
|
+
// _id: z.string(),
|
|
5363
|
+
// stat: z.number(),
|
|
5364
|
+
// docType: z.string(),
|
|
5365
|
+
// docDate: z.number(),
|
|
5366
|
+
// ts: z.number(),
|
|
5367
|
+
// order_ts: z.number(),
|
|
5368
|
+
// studio_meta: z.object({
|
|
5369
|
+
// created: z.number(),
|
|
5370
|
+
// createdByUid: z.string(),
|
|
5371
|
+
// checkedInUserId: z.string(),
|
|
5372
|
+
// savedByUid: z.string(),
|
|
5373
|
+
// checkedInUserName: z.string(),
|
|
5374
|
+
// parentId: z.string(),
|
|
5375
|
+
// source: z.string(),
|
|
5376
|
+
// }),
|
|
5377
|
+
// properties: z.object({
|
|
5378
|
+
// menuName: z.string(),
|
|
5379
|
+
// menuType: z.string(),
|
|
5380
|
+
// databaseSocket: z.string(),
|
|
5381
|
+
// }),
|
|
5382
|
+
// progDataSource: z.object({}),
|
|
5383
|
+
// progFields: z.array(z.object({})),
|
|
5384
|
+
// progEvents: z.array(z.object({})),
|
|
5385
|
+
// }),
|
|
5386
|
+
// ),
|
|
5387
|
+
// },
|
|
5388
|
+
// },
|
|
5389
|
+
// };
|
|
5390
|
+
|
|
5391
|
+
// if (object_unit === 'app') {
|
|
5392
|
+
// const agents_as_a_tool_arr = get_agents_as_a_tool(['table', 'folder', 'component', 'get_data']);
|
|
5393
|
+
// studio_agents_obj.app.tools = [...studio_agents_obj.app.tools, ...agents_as_a_tool_arr];
|
|
5394
|
+
// }
|
|
5395
|
+
|
|
5396
|
+
// const run = async function (user_prompt, object_unit) {
|
|
5397
|
+
// const _agent = new Agent(studio_agents_obj[object_unit]);
|
|
5398
|
+
// const runner = new Runner();
|
|
5399
|
+
|
|
5400
|
+
// const result = await runner.run(_agent, user_prompt, {
|
|
5401
|
+
// context: { uid, app_id, userName },
|
|
5402
|
+
// });
|
|
5403
|
+
|
|
5404
|
+
// return result;
|
|
5405
|
+
// };
|
|
5406
|
+
|
|
5407
|
+
// const result = await run(user_prompt, object_unit);
|
|
5408
|
+
|
|
5409
|
+
// return { code: 100, data: result.finalOutput };
|
|
5410
|
+
// } catch (err) {
|
|
5411
|
+
// debugger;
|
|
5412
|
+
// console.error('>>>>> AI:', err);
|
|
5413
|
+
// console.error('Cause:', err?.cause?.message);
|
|
5414
|
+
// return { code: -100, data: err.message };
|
|
5415
|
+
// }
|
|
5416
|
+
// };
|
|
5417
|
+
|
|
5418
|
+
// export const get_chat_conversation = async function (req) {
|
|
5419
|
+
// let { conversation_id, order = 'asc', limit, after, _id, uid } = req;
|
|
5420
|
+
|
|
5421
|
+
// const account_profile_info = await account_module.get_active_account_profile_info(uid);
|
|
5422
|
+
|
|
5423
|
+
// if (_id) {
|
|
5424
|
+
|
|
5425
|
+
// let data = await db_module.get_app_couch_doc(account_profile_info.app_id, _id);
|
|
5426
|
+
// return data;
|
|
5427
|
+
// }
|
|
5428
|
+
|
|
5429
|
+
// try {
|
|
5430
|
+
// // const project_db = await get_account_project_db(uid);
|
|
5431
|
+
// // let conversation_doc = await project_db.get(conversation_id);
|
|
5432
|
+
// let conversation_doc = await db_module.get_app_couch_doc(account_profile_info.app_id, conversation_id);
|
|
5433
|
+
// let reference_doc;
|
|
5434
|
+
// if (conversation_doc.shared_from_uid) {
|
|
5435
|
+
// reference_doc = _.cloneDeep(conversation_doc);
|
|
5436
|
+
// conversation_doc = await db_module.get_app_couch_doc_native(reference_doc.shared_from_app_id, reference_doc.share_item_id);
|
|
5437
|
+
// conversation_doc.reference_doc = reference_doc;
|
|
5438
|
+
// }
|
|
5439
|
+
// let conversation = await client.conversations.items.list(conversation_id, { limit, order, after });
|
|
5440
|
+
|
|
5441
|
+
// return { code: 15, data: { conversation, ...conversation_doc } };
|
|
5442
|
+
// } catch (err) {
|
|
5443
|
+
// return { code: -15, data: err.message };
|
|
5444
|
+
// }
|
|
5445
|
+
// };
|