@xuda.io/ai_module 1.1.5644 → 1.1.5645

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 +51 -6
  2. package/package.json +1 -1
package/index.mjs CHANGED
@@ -345,6 +345,7 @@ const LIST_SORT_PATHS = {
345
345
  };
346
346
 
347
347
  const account_ms = await import(`${module_path}/account_module/index_ms.mjs`);
348
+ const ticket_ms = await import(`${module_path}/ticket_module/index_ms.mjs`);
348
349
  const drive_ms = await import(`${module_path}/drive_module/index_ms.mjs`);
349
350
  const jobs_ms = await import(`${module_path}/jobs_module/index_ms.mjs`);
350
351
  const team_ms = await import(`${module_path}/team_module/index_ms.mjs`);
@@ -4711,7 +4712,7 @@ export const classify_external_app_scan = async (req) => {
4711
4712
  }
4712
4713
  };
4713
4714
 
4714
- // Triage a CPI error incident for the central error resolver (support_module).
4715
+ // Triage a CPI error incident for the central error resolver (ticket_module).
4715
4716
  // The Zod schema lives here because zodTextFormat schemas cannot cross the
4716
4717
  // message broker (it JSON-serializes args and strips functions). The resolver
4717
4718
  // passes a plain-JSON { incident, catalog_entry } payload and gets back a plain
@@ -5002,10 +5003,17 @@ const get_error_message = function (err, fallback = 'Unknown error') {
5002
5003
  };
5003
5004
 
5004
5005
  const get_plugin_import_specifier = function (app_id, plugin_name, resource, dev = true) {
5005
- const absolute_path = dev ? path.join(process.env.XUDA_HOME, 'plugins', plugin_name, resource) : path.join(_conf.plugins_drive_path, app_id, 'node_modules', plugin_name, resource);
5006
+ // `dev` asks for the repo working copy under $XUDA_HOME/plugins, which only
5007
+ // exists on the debug box. Anywhere else (master, the regions) that directory
5008
+ // is absent, so the plugin has to be the npm copy installed into the app's own
5009
+ // plugins folder. Without the is_debug gate every plugin-backed agent tool
5010
+ // resolved to a path that does not exist in production.
5011
+ const use_source = dev && _conf.is_debug;
5012
+ const absolute_path = use_source ? path.join(process.env.XUDA_HOME, 'plugins', plugin_name, resource) : path.join(_conf.plugins_drive_path, app_id, 'node_modules', plugin_name, resource);
5006
5013
 
5007
5014
  const file_url = pathToFileURL(absolute_path);
5008
- if (dev) {
5015
+ if (use_source) {
5016
+ // Cache-bust so an edit to the working copy is picked up without a restart.
5009
5017
  file_url.searchParams.set('ts', `${Date.now()}`);
5010
5018
  }
5011
5019
 
@@ -9112,7 +9120,9 @@ const run_plugin = async function (app_id, uid, plugin_name, method, prop_data,
9112
9120
  const fields = await get_fields_data(methods[method].fields, prop_data);
9113
9121
  const params = fields;
9114
9122
  const env = { couch, app_id, uid, userName, agent_info };
9115
- const setup_doc = plugin_doc.setup || { OPENAI_API_KEY: _conf.OPENAI_API_KEY };
9123
+ // Platform credentials come from the box's secrets at call time, never from
9124
+ // the plugin package or a stored per-app copy. See with_platform_plugin_secrets.
9125
+ const setup_doc = _common.with_platform_plugin_secrets(plugin_doc.setup);
9116
9126
 
9117
9127
  ///////////////////////
9118
9128
  const execute_server_script = async function (req, app_id_reference, server_script, method, params, setup_doc) {
@@ -9237,7 +9247,9 @@ const get_plugin_tool = async function (app_id, uid, plugin_name, method, prop_d
9237
9247
  const fields = await get_fields_data(_method.fields, prop_data);
9238
9248
  const params = fields;
9239
9249
  const env = { couch, app_id, uid, userName, agent_info, account_profile_obj };
9240
- const setup_doc = plugin_doc.setup || { OPENAI_API_KEY: _conf.OPENAI_API_KEY };
9250
+ // Platform credentials come from the box's secrets at call time, never from
9251
+ // the plugin package or a stored per-app copy. See with_platform_plugin_secrets.
9252
+ const setup_doc = _common.with_platform_plugin_secrets(plugin_doc.setup);
9241
9253
 
9242
9254
  ///////////////////////
9243
9255
  const execute_server_script = async function (req, app_id_reference, server_script, method, params, setup_doc) {
@@ -17407,7 +17419,40 @@ export const contact_form_submit = async function (req, job_id, headers) {
17407
17419
  const body_parts = [message];
17408
17420
  const detail_bits = [phone && `Phone: ${phone}`, company && `Company: ${company}`].filter(Boolean);
17409
17421
  if (detail_bits.length) body_parts.push(detail_bits.join(' | '));
17410
- await _contact_form_create_ticket(account_profile_info, contact_id, subject, body_parts.join('\n\n'), origin);
17422
+ const _conv = await _contact_form_create_ticket(account_profile_info, contact_id, subject, body_parts.join('\n\n'), origin);
17423
+
17424
+ // Source 6 of docs/plans/xuda-tickets.md. The conversation above stays the
17425
+ // human-readable thread and the contact mirror; this ALSO files the uniform
17426
+ // ticket so a contact-form submission shows up in the Tickets manager next
17427
+ // to every other source, with the same status, topic, action and SLA. Best
17428
+ // effort on purpose: the visitor already has their conversation, so a
17429
+ // ticketing failure must never fail the submission.
17430
+ try {
17431
+ const _tk = await ticket_ms.ticket_submit({
17432
+ source: 'profile_contact_form',
17433
+ channel: 'form',
17434
+ owner_uid: account_profile_info.uid,
17435
+ owner_profile_id: account_profile_info.account_profile_id,
17436
+ name,
17437
+ email,
17438
+ phone,
17439
+ company,
17440
+ subject,
17441
+ details: body_parts.join('\n\n'),
17442
+ origin: String(origin || '').slice(0, 200),
17443
+ });
17444
+ // Link both ways so the manager can jump to the thread and vice versa.
17445
+ if (_tk?.code > 0 && _tk.data?._id && _conv?._id) {
17446
+ const _c = await db_module.get_app_couch_doc(account_profile_info.app_id, _conv._id);
17447
+ if (_c.code > -1 && _c.data) {
17448
+ _c.data.ticket_id = _tk.data._id;
17449
+ _c.data.ticket_no = _tk.data.ticket_no;
17450
+ await db_module.save_app_couch_doc(account_profile_info.app_id, _c.data);
17451
+ }
17452
+ }
17453
+ } catch (tk_err) {
17454
+ console.warn('[contact_form] uniform ticket not filed:', tk_err.message);
17455
+ }
17411
17456
 
17412
17457
  // Owner notification email (platform template).
17413
17458
  if (config.notify_email !== false) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xuda.io/ai_module",
3
- "version": "1.1.5644",
3
+ "version": "1.1.5645",
4
4
  "description": "Xuda AI Module",
5
5
  "main": "index.mjs",
6
6
  "type": "module",