@xuda.io/ai_module 1.1.5595 → 1.1.5596
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 +403 -1
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -4375,7 +4375,7 @@ export const submit_chat_conversation = async function (req, job_id, headers) {
|
|
|
4375
4375
|
}
|
|
4376
4376
|
|
|
4377
4377
|
case 'dashboard': {
|
|
4378
|
-
|
|
4378
|
+
ret = await dashboard_chat(req, job_id, headers);
|
|
4379
4379
|
break;
|
|
4380
4380
|
}
|
|
4381
4381
|
|
|
@@ -5058,6 +5058,408 @@ ${conversation_history || `User (studio): ${prompt}`}
|
|
|
5058
5058
|
}
|
|
5059
5059
|
};
|
|
5060
5060
|
|
|
5061
|
+
const get_dashboard_chat_context = function (req, conversation_doc) {
|
|
5062
|
+
return (req.context || req.dashboard_context || req.metadata?.context || conversation_doc.context || conversation_doc.dashboard_context || conversation_doc.metadata?.context || '').toString().trim().toLowerCase();
|
|
5063
|
+
};
|
|
5064
|
+
|
|
5065
|
+
const get_dashboard_cpi_keywords = function (context, prompt = '') {
|
|
5066
|
+
const haystack = `${context || ''} ${prompt || ''}`.toLowerCase();
|
|
5067
|
+
const keyword_sets = {
|
|
5068
|
+
data: ['data', 'database', 'db', 'dbs', 'table', 'tables', 'couch', 'read', 'create', 'update', 'delete', 'restore', 'count'],
|
|
5069
|
+
account: ['account', 'profile', 'profiles', 'user', 'users', 'contact', 'contacts', 'member', 'members', 'share', 'team'],
|
|
5070
|
+
apps: ['app', 'apps', 'project', 'projects', 'config', 'backup', 'release', 'notification', 'studio', 'mini'],
|
|
5071
|
+
deploy: ['deploy', 'deployment', 'instance', 'server', 'region', 'domain', 'dns', 'traffic', 'firewall', 'usage', 'build'],
|
|
5072
|
+
drive: ['drive', 'file', 'files', 'folder', 'upload', 'extract', 'rename', 'workspace'],
|
|
5073
|
+
plugins: ['plugin', 'plugins', 'install', 'uninstall', 'category', 'categories'],
|
|
5074
|
+
email: ['email', 'mailbox', 'mailboxes', 'mail'],
|
|
5075
|
+
logs: ['log', 'logs', 'security', 'session', 'traffic'],
|
|
5076
|
+
ai: ['ai', 'chat', 'agent', 'workspace', 'conversation'],
|
|
5077
|
+
};
|
|
5078
|
+
|
|
5079
|
+
for (const [key, keywords] of Object.entries(keyword_sets)) {
|
|
5080
|
+
if (haystack.includes(key) || keywords.some((keyword) => haystack.includes(keyword))) {
|
|
5081
|
+
return keywords;
|
|
5082
|
+
}
|
|
5083
|
+
}
|
|
5084
|
+
|
|
5085
|
+
return [];
|
|
5086
|
+
};
|
|
5087
|
+
|
|
5088
|
+
const get_dashboard_cpi_zod_item = function (key, val = {}) {
|
|
5089
|
+
let schema;
|
|
5090
|
+
|
|
5091
|
+
if (val.enum?.length) {
|
|
5092
|
+
schema = z.enum(val.enum);
|
|
5093
|
+
} else {
|
|
5094
|
+
switch (val.type) {
|
|
5095
|
+
case 'string':
|
|
5096
|
+
schema = z.string();
|
|
5097
|
+
break;
|
|
5098
|
+
case 'number':
|
|
5099
|
+
case 'integer':
|
|
5100
|
+
schema = z.number();
|
|
5101
|
+
if (val.type === 'integer') schema = schema.int();
|
|
5102
|
+
break;
|
|
5103
|
+
case 'boolean':
|
|
5104
|
+
schema = z.boolean();
|
|
5105
|
+
break;
|
|
5106
|
+
case 'array':
|
|
5107
|
+
schema = z.array(get_dashboard_cpi_zod_item('', val.items || { type: 'any' }));
|
|
5108
|
+
break;
|
|
5109
|
+
case 'object': {
|
|
5110
|
+
const props = {};
|
|
5111
|
+
const fields = val.items?.properties || val.properties || {};
|
|
5112
|
+
const required = val.items?.required || val.required || [];
|
|
5113
|
+
for (const [item_key, item_val] of Object.entries(fields)) {
|
|
5114
|
+
props[item_key] = get_dashboard_cpi_zod_item(item_key, item_val);
|
|
5115
|
+
if (!required.includes(item_key)) {
|
|
5116
|
+
props[item_key] = props[item_key].optional();
|
|
5117
|
+
}
|
|
5118
|
+
}
|
|
5119
|
+
schema = z.object(props);
|
|
5120
|
+
break;
|
|
5121
|
+
}
|
|
5122
|
+
default:
|
|
5123
|
+
schema = z.any();
|
|
5124
|
+
break;
|
|
5125
|
+
}
|
|
5126
|
+
}
|
|
5127
|
+
|
|
5128
|
+
if (!val.mandatory) {
|
|
5129
|
+
schema = schema.optional();
|
|
5130
|
+
}
|
|
5131
|
+
|
|
5132
|
+
const valid_values = val.options?.length ? ` Valid values: ${val.options.join(', ')}.` : '';
|
|
5133
|
+
const desc = val.description ? `${val.name || key.replace(/_/g, ' ')} - ${val.description}${valid_values}` : valid_values;
|
|
5134
|
+
return desc ? schema.describe(desc) : schema;
|
|
5135
|
+
};
|
|
5136
|
+
|
|
5137
|
+
const get_dashboard_cpi_tools = function ({ uid, profile_id, gtp_token, app_id, context, prompt }) {
|
|
5138
|
+
const keywords = get_dashboard_cpi_keywords(context, prompt);
|
|
5139
|
+
const tools = [];
|
|
5140
|
+
const selected_methods = [];
|
|
5141
|
+
const method_entries = [];
|
|
5142
|
+
|
|
5143
|
+
for (const [method_name, method_prop] of Object.entries(_conf.cpi_methods || {})) {
|
|
5144
|
+
if (!method_prop) continue;
|
|
5145
|
+
if (method_prop.private) continue;
|
|
5146
|
+
if (!method_prop.description && !method_prop.tooltip) continue;
|
|
5147
|
+
|
|
5148
|
+
const method_text = `${method_name} ${method_prop.name || ''} ${method_prop.description || ''} ${method_prop.tooltip || ''} ${method_prop.microservice || ''}`.toLowerCase();
|
|
5149
|
+
if (keywords.length && !keywords.some((keyword) => method_text.includes(keyword))) continue;
|
|
5150
|
+
|
|
5151
|
+
method_entries.push({ method_name, method_prop, score: method_prop.mcp ? 2 : 1 });
|
|
5152
|
+
}
|
|
5153
|
+
|
|
5154
|
+
method_entries.sort((a, b) => b.score - a.score || a.method_name.localeCompare(b.method_name));
|
|
5155
|
+
|
|
5156
|
+
for (const { method_name, method_prop } of method_entries.slice(0, 96)) {
|
|
5157
|
+
const inputSchema = {};
|
|
5158
|
+
for (const [field_key, field_val] of Object.entries(method_prop.fields || {})) {
|
|
5159
|
+
inputSchema[field_key] = get_dashboard_cpi_zod_item(field_key, field_val);
|
|
5160
|
+
}
|
|
5161
|
+
|
|
5162
|
+
selected_methods.push(method_name);
|
|
5163
|
+
tools.push(
|
|
5164
|
+
tool({
|
|
5165
|
+
name: method_name.substring(0, 60),
|
|
5166
|
+
description: method_prop.description || method_prop.tooltip || method_name,
|
|
5167
|
+
parameters: z.object(inputSchema),
|
|
5168
|
+
async execute(params) {
|
|
5169
|
+
try {
|
|
5170
|
+
const response = await fetch(`http://localhost:3007/cpi/${method_name}`, {
|
|
5171
|
+
method: 'POST',
|
|
5172
|
+
headers: {
|
|
5173
|
+
Accept: 'application/json',
|
|
5174
|
+
'Content-Type': 'application/json',
|
|
5175
|
+
},
|
|
5176
|
+
body: JSON.stringify({
|
|
5177
|
+
...params,
|
|
5178
|
+
uid,
|
|
5179
|
+
profile_id,
|
|
5180
|
+
app_id,
|
|
5181
|
+
reference_id: app_id,
|
|
5182
|
+
gtp_token,
|
|
5183
|
+
}),
|
|
5184
|
+
});
|
|
5185
|
+
const ret = await response.json();
|
|
5186
|
+
return JSON.stringify(ret || '', null, 2);
|
|
5187
|
+
} catch (err) {
|
|
5188
|
+
return `CPI method ${method_name} failed: ${err.message}`;
|
|
5189
|
+
}
|
|
5190
|
+
},
|
|
5191
|
+
}),
|
|
5192
|
+
);
|
|
5193
|
+
}
|
|
5194
|
+
|
|
5195
|
+
return { tools, selected_methods };
|
|
5196
|
+
};
|
|
5197
|
+
|
|
5198
|
+
const dashboard_chat = async function (req, job_id, headers) {
|
|
5199
|
+
const { uid, profile_id, gtp_token } = req;
|
|
5200
|
+
const account_profile_info = await get_active_account_profile_info(uid, profile_id);
|
|
5201
|
+
let { prompt, conversation_doc, attachments = [], stream = true, ai_model = _conf.default_ai_model, metadata = {} } = req;
|
|
5202
|
+
|
|
5203
|
+
const conversation_id = conversation_doc._id;
|
|
5204
|
+
const dashboard_context = get_dashboard_chat_context(req, conversation_doc);
|
|
5205
|
+
const target_app_id = (await _common.get_project_app_id(req.app_id || conversation_doc.reference_id || account_profile_info.app_id, true)) || account_profile_info.app_id;
|
|
5206
|
+
const prompt_conversation_item_id = await _common.xuda_get_uuid('chat_conversation_item');
|
|
5207
|
+
const response_conversation_item_id = await _common.xuda_get_uuid('chat_conversation_item');
|
|
5208
|
+
const request_started_at = Date.now();
|
|
5209
|
+
|
|
5210
|
+
let stream_delta_seq = 0;
|
|
5211
|
+
let stream_delta_text = '';
|
|
5212
|
+
const emitToDashboard = (type, content, params) => {
|
|
5213
|
+
const is_stream_delta = type === 'stream_delta';
|
|
5214
|
+
const is_stream_end = type === 'stream_end';
|
|
5215
|
+
const seq = is_stream_delta ? ++stream_delta_seq : undefined;
|
|
5216
|
+
if (is_stream_delta) {
|
|
5217
|
+
stream_delta_text += content || '';
|
|
5218
|
+
}
|
|
5219
|
+
ws_dashboard_msa.emit_message_to_dashboard({
|
|
5220
|
+
service: type,
|
|
5221
|
+
to: uid,
|
|
5222
|
+
data: {
|
|
5223
|
+
conversation_id,
|
|
5224
|
+
job_id,
|
|
5225
|
+
delta: content,
|
|
5226
|
+
...(type === 'stream_start' ? { request_started_at } : {}),
|
|
5227
|
+
...(seq ? { seq } : {}),
|
|
5228
|
+
...(is_stream_end
|
|
5229
|
+
? {
|
|
5230
|
+
stream_id: response_conversation_item_id,
|
|
5231
|
+
final_seq: stream_delta_seq,
|
|
5232
|
+
text: stream_delta_text,
|
|
5233
|
+
}
|
|
5234
|
+
: {}),
|
|
5235
|
+
prompt_conversation_item_id,
|
|
5236
|
+
response_conversation_item_id,
|
|
5237
|
+
params,
|
|
5238
|
+
},
|
|
5239
|
+
});
|
|
5240
|
+
};
|
|
5241
|
+
|
|
5242
|
+
const streamText = function (text, chunk_size = 280) {
|
|
5243
|
+
if (!stream || !text) return;
|
|
5244
|
+
for (let i = 0; i < text.length; i += chunk_size) {
|
|
5245
|
+
emitToDashboard('stream_delta', text.slice(i, i + chunk_size));
|
|
5246
|
+
}
|
|
5247
|
+
};
|
|
5248
|
+
|
|
5249
|
+
const saveUserItem = async function () {
|
|
5250
|
+
const conversation_item_reference_id = await add_conversation_item(uid, profile_id, conversation_id, prompt, 'dashboard', conversation_doc.reference_id, { context: dashboard_context, target_app_id });
|
|
5251
|
+
const out_conversation_item_obj = {
|
|
5252
|
+
_id: prompt_conversation_item_id,
|
|
5253
|
+
stat: 3,
|
|
5254
|
+
docType: 'chat_conversation_item',
|
|
5255
|
+
uid,
|
|
5256
|
+
conversation_type: 'dashboard',
|
|
5257
|
+
type: 'dashboard',
|
|
5258
|
+
date_created_ts: Date.now(),
|
|
5259
|
+
ts: Date.now(),
|
|
5260
|
+
conversation_id,
|
|
5261
|
+
text: prompt,
|
|
5262
|
+
reference_id: conversation_doc.reference_id,
|
|
5263
|
+
conversation_item_reference_id,
|
|
5264
|
+
direction: 'out',
|
|
5265
|
+
role: 'user',
|
|
5266
|
+
read: { [uid]: Date.now() },
|
|
5267
|
+
rtl: _common.detectRTL(prompt),
|
|
5268
|
+
job_id,
|
|
5269
|
+
context: dashboard_context,
|
|
5270
|
+
target_app_id,
|
|
5271
|
+
metadata,
|
|
5272
|
+
};
|
|
5273
|
+
|
|
5274
|
+
const save_ret = await db_module.save_app_couch_doc(account_profile_info.app_id, out_conversation_item_obj);
|
|
5275
|
+
if (save_ret.code < 0) throw new Error(save_ret.data);
|
|
5276
|
+
return save_ret;
|
|
5277
|
+
};
|
|
5278
|
+
|
|
5279
|
+
const saveAssistantItem = async function (text, extra = {}) {
|
|
5280
|
+
const in_conversation_item_obj = {
|
|
5281
|
+
_id: response_conversation_item_id,
|
|
5282
|
+
stat: 3,
|
|
5283
|
+
docType: 'chat_conversation_item',
|
|
5284
|
+
uid,
|
|
5285
|
+
conversation_type: 'dashboard',
|
|
5286
|
+
type: 'dashboard',
|
|
5287
|
+
date_created_ts: Date.now(),
|
|
5288
|
+
ts: Date.now(),
|
|
5289
|
+
conversation_id,
|
|
5290
|
+
text,
|
|
5291
|
+
reference_id: conversation_doc.reference_id,
|
|
5292
|
+
direction: 'in',
|
|
5293
|
+
role: 'assistant',
|
|
5294
|
+
read: { [uid]: Date.now() },
|
|
5295
|
+
rtl: _common.detectRTL(text),
|
|
5296
|
+
job_id,
|
|
5297
|
+
context: dashboard_context,
|
|
5298
|
+
target_app_id,
|
|
5299
|
+
prompt_conversation_item_id,
|
|
5300
|
+
...extra,
|
|
5301
|
+
};
|
|
5302
|
+
|
|
5303
|
+
return await db_module.save_app_couch_doc_native(account_profile_info.app_id, in_conversation_item_obj);
|
|
5304
|
+
};
|
|
5305
|
+
|
|
5306
|
+
const formatDashboardHistoryItem = function (item) {
|
|
5307
|
+
const role = item.role === 'assistant' ? 'Assistant' : 'User';
|
|
5308
|
+
const type = item.conversation_type || item.type || 'message';
|
|
5309
|
+
const file_name = item?.file?.filename ? ` file=${item.file.filename}` : '';
|
|
5310
|
+
let text = (item.text || item.prompt || '').trim();
|
|
5311
|
+
if (text.length > 2500) {
|
|
5312
|
+
text = `${text.slice(0, 2500)}...`;
|
|
5313
|
+
}
|
|
5314
|
+
|
|
5315
|
+
return `${role} (${type}${file_name}): ${text}`;
|
|
5316
|
+
};
|
|
5317
|
+
|
|
5318
|
+
const getDashboardContextPrompt = async function () {
|
|
5319
|
+
const ret = await db_module.find_app_couch_query(account_profile_info.app_id, {
|
|
5320
|
+
selector: {
|
|
5321
|
+
docType: 'chat_conversation_item',
|
|
5322
|
+
conversation_id,
|
|
5323
|
+
stat: 3,
|
|
5324
|
+
},
|
|
5325
|
+
limit: 12,
|
|
5326
|
+
sort: [{ date_created_ts: 'desc' }],
|
|
5327
|
+
});
|
|
5328
|
+
|
|
5329
|
+
const items = (ret.docs || []).reverse().filter((item) => item.text || item.prompt || item?.file?.filename);
|
|
5330
|
+
const conversation_history = items.map(formatDashboardHistoryItem).join('\n\n');
|
|
5331
|
+
|
|
5332
|
+
return `You are handling the latest Xuda dashboard chat request.
|
|
5333
|
+
|
|
5334
|
+
Dashboard context/tab: ${dashboard_context || 'unknown'}
|
|
5335
|
+
Target app_id/reference_id: ${target_app_id}
|
|
5336
|
+
|
|
5337
|
+
Use the conversation history, attachment transcripts, and latest user message to infer the dashboard area when context is unknown.
|
|
5338
|
+
|
|
5339
|
+
Conversation history:
|
|
5340
|
+
${conversation_history || `User (dashboard): ${prompt}`}
|
|
5341
|
+
`;
|
|
5342
|
+
};
|
|
5343
|
+
|
|
5344
|
+
try {
|
|
5345
|
+
emitToDashboard('stream_start');
|
|
5346
|
+
emitToDashboard('stream_phase', dashboard_context === 'console' ? 'Starting console request' : 'Starting dashboard request');
|
|
5347
|
+
|
|
5348
|
+
await saveUserItem();
|
|
5349
|
+
|
|
5350
|
+
if (attachments?.length) {
|
|
5351
|
+
emitToDashboard('stream_phase', 'Analyzing attachments', { update: true });
|
|
5352
|
+
await attachment_handler(uid, account_profile_info.app_id, conversation_id, attachments, account_profile_info);
|
|
5353
|
+
}
|
|
5354
|
+
|
|
5355
|
+
conversation_doc = await db_module.get_app_couch_doc_native(account_profile_info.app_id, conversation_id);
|
|
5356
|
+
conversation_doc.ts = Date.now();
|
|
5357
|
+
conversation_doc.stat = 2;
|
|
5358
|
+
conversation_doc.request_started_at = request_started_at;
|
|
5359
|
+
conversation_doc.job_id = job_id;
|
|
5360
|
+
conversation_doc.context = dashboard_context;
|
|
5361
|
+
conversation_doc.target_app_id = target_app_id;
|
|
5362
|
+
await db_module.save_app_couch_doc_native(account_profile_info.app_id, conversation_doc);
|
|
5363
|
+
|
|
5364
|
+
if (dashboard_context === 'console') {
|
|
5365
|
+
const codex_ret = await execute_codex_request({ ...req, conversation_id, conversation_doc, prompt, attachments, stream: false }, job_id, headers);
|
|
5366
|
+
const codex_events = codex_ret?.data?.events || [];
|
|
5367
|
+
const last_message = [...codex_events].reverse().find((event) => event?.item?.type === 'agent_message' && event.item.text)?.item?.text;
|
|
5368
|
+
const response_text = codex_ret.code < 0 ? `Console request failed: ${get_error_message(codex_ret.data, 'Codex request failed')}` : last_message || 'Console request completed.';
|
|
5369
|
+
|
|
5370
|
+
emitToDashboard('response_start');
|
|
5371
|
+
streamText(response_text);
|
|
5372
|
+
emitToDashboard('stream_end');
|
|
5373
|
+
|
|
5374
|
+
conversation_doc = await db_module.get_app_couch_doc_native(account_profile_info.app_id, conversation_id);
|
|
5375
|
+
conversation_doc.ts = Date.now();
|
|
5376
|
+
conversation_doc.stat = 3;
|
|
5377
|
+
conversation_doc.process_stat = codex_ret.code < 0 ? 'partial' : 'full';
|
|
5378
|
+
await db_module.save_app_couch_doc_native(account_profile_info.app_id, conversation_doc);
|
|
5379
|
+
|
|
5380
|
+
return await saveAssistantItem(response_text, { codex_result: codex_ret });
|
|
5381
|
+
}
|
|
5382
|
+
|
|
5383
|
+
const dashboard_prompt = await getDashboardContextPrompt();
|
|
5384
|
+
const app_obj = await get_app_obj(target_app_id);
|
|
5385
|
+
const userName = await account_ms.get_user_name(uid);
|
|
5386
|
+
const account_info = (await get_account_name({ uid })).data;
|
|
5387
|
+
const context = { ...{ app_id: target_app_id, uid, profile_id, userName, account_info, app_obj, account_id: uid, dashboard_context }, ...extractClientInfo(headers) };
|
|
5388
|
+
const cpi_tools_ret = get_dashboard_cpi_tools({ uid, profile_id, gtp_token, app_id: target_app_id, context: dashboard_context, prompt: dashboard_prompt });
|
|
5389
|
+
|
|
5390
|
+
if (!cpi_tools_ret.tools.length) {
|
|
5391
|
+
throw new Error(`no CPI methods available for dashboard context "${dashboard_context || 'unknown'}"`);
|
|
5392
|
+
}
|
|
5393
|
+
|
|
5394
|
+
const agent = new Agent({
|
|
5395
|
+
name: 'Dashboard CPI Agent',
|
|
5396
|
+
instructions: `
|
|
5397
|
+
You are Xuda dashboard chat.
|
|
5398
|
+
The user is interacting with the dashboard tab/context "${dashboard_context || 'unknown'}" for app_id "${target_app_id}".
|
|
5399
|
+
Use the available CPI tools to inspect, update, or explain dashboard data. Prefer tool calls over guessing.
|
|
5400
|
+
If the screenshot or prompt implies the tab/context, infer the relevant dashboard area and choose the closest CPI method.
|
|
5401
|
+
For data/database requests, use the database/table CPI methods and keep app_id/reference_id anchored to "${target_app_id}".
|
|
5402
|
+
Summarize the action and important CPI result fields clearly. Do not invent successful changes; report tool errors as errors.
|
|
5403
|
+
Available CPI methods: ${cpi_tools_ret.selected_methods.join(', ')}
|
|
5404
|
+
`.trim(),
|
|
5405
|
+
model: ai_model,
|
|
5406
|
+
tools: cpi_tools_ret.tools,
|
|
5407
|
+
});
|
|
5408
|
+
|
|
5409
|
+
agent.on('agent_tool_start', (context, tool) => {
|
|
5410
|
+
emitToDashboard('stream_phase', `Starting ${tool?.name?.replaceAll('_', ' ')} tool`, { update: true });
|
|
5411
|
+
});
|
|
5412
|
+
|
|
5413
|
+
emitToDashboard('stream_phase', 'Submitting dashboard request', { update: true });
|
|
5414
|
+
const runner = new Runner();
|
|
5415
|
+
const output = await runner.run(agent, dashboard_prompt, { context, stream });
|
|
5416
|
+
let response_text = '';
|
|
5417
|
+
|
|
5418
|
+
if (stream) {
|
|
5419
|
+
const output_stream = output.toTextStream({ compatibleWithNodeStreams: true });
|
|
5420
|
+
let response_started = false;
|
|
5421
|
+
for await (const chunk of output_stream) {
|
|
5422
|
+
if (!response_started) {
|
|
5423
|
+
response_started = true;
|
|
5424
|
+
emitToDashboard('stream_phase', 'Streaming results', { update: true });
|
|
5425
|
+
emitToDashboard('response_start');
|
|
5426
|
+
}
|
|
5427
|
+
const text = chunk.toString();
|
|
5428
|
+
response_text += text;
|
|
5429
|
+
emitToDashboard('stream_delta', text);
|
|
5430
|
+
}
|
|
5431
|
+
}
|
|
5432
|
+
|
|
5433
|
+
response_text = response_text || output?.state?._currentStep?.output || output?.finalOutput || output?.output || 'Dashboard request completed.';
|
|
5434
|
+
emitToDashboard('stream_end');
|
|
5435
|
+
|
|
5436
|
+
conversation_doc = await db_module.get_app_couch_doc_native(account_profile_info.app_id, conversation_id);
|
|
5437
|
+
conversation_doc.ts = Date.now();
|
|
5438
|
+
conversation_doc.stat = 3;
|
|
5439
|
+
conversation_doc.process_stat = 'full';
|
|
5440
|
+
await db_module.save_app_couch_doc_native(account_profile_info.app_id, conversation_doc);
|
|
5441
|
+
|
|
5442
|
+
return await saveAssistantItem(response_text, {
|
|
5443
|
+
cpi_methods: cpi_tools_ret.selected_methods,
|
|
5444
|
+
ai_agent_id: 'dashboard_cpi_agent',
|
|
5445
|
+
});
|
|
5446
|
+
} catch (err) {
|
|
5447
|
+
const error_message = get_error_message(err, 'dashboard request failed');
|
|
5448
|
+
emitToDashboard('stream_phase', 'Dashboard request failed', { update: true });
|
|
5449
|
+
emitToDashboard('response_start');
|
|
5450
|
+
streamText(`Dashboard request failed: ${error_message}`);
|
|
5451
|
+
emitToDashboard('stream_end');
|
|
5452
|
+
|
|
5453
|
+
conversation_doc = await db_module.get_app_couch_doc_native(account_profile_info.app_id, conversation_id);
|
|
5454
|
+
conversation_doc.ts = Date.now();
|
|
5455
|
+
conversation_doc.stat = 3;
|
|
5456
|
+
conversation_doc.process_stat = 'partial';
|
|
5457
|
+
await db_module.save_app_couch_doc_native(account_profile_info.app_id, conversation_doc);
|
|
5458
|
+
|
|
5459
|
+
return { code: -17, data: error_message };
|
|
5460
|
+
}
|
|
5461
|
+
};
|
|
5462
|
+
|
|
5061
5463
|
const get_ai_agent_tools = async function ({ ai_agent_doc, agent_id, reference_type, prompt_suggestion_activated, chat_suggestion_activated, gtp_token, uid, account_profile_info, job_id, headers, context, app_id }) {
|
|
5062
5464
|
let tools = [];
|
|
5063
5465
|
let tool_resources = {};
|