@resolveio/server-lib 22.1.24 → 22.1.26

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.
@@ -59,6 +59,10 @@ var schema = {
59
59
  type: String,
60
60
  optional: true
61
61
  },
62
+ id_user: {
63
+ type: String,
64
+ optional: true
65
+ },
62
66
  id_app: {
63
67
  type: String,
64
68
  optional: true
@@ -119,11 +123,14 @@ setTimeout(function () { return __awaiter(void 0, void 0, void 0, function () {
119
123
  case 0: return [4 /*yield*/, exports.AiTerminalConversations.createIndex({ id_client: 1, updatedAt: -1 })];
120
124
  case 1:
121
125
  _a.sent();
122
- return [4 /*yield*/, exports.AiTerminalConversations.createIndex({ id_app: 1, updatedAt: -1 })];
126
+ return [4 /*yield*/, exports.AiTerminalConversations.createIndex({ id_user: 1, updatedAt: -1 })];
123
127
  case 2:
124
128
  _a.sent();
125
- return [4 /*yield*/, exports.AiTerminalConversations.createIndex({ status: 1, updatedAt: -1 })];
129
+ return [4 /*yield*/, exports.AiTerminalConversations.createIndex({ id_app: 1, updatedAt: -1 })];
126
130
  case 3:
131
+ _a.sent();
132
+ return [4 /*yield*/, exports.AiTerminalConversations.createIndex({ status: 1, updatedAt: -1 })];
133
+ case 4:
127
134
  _a.sent();
128
135
  return [2 /*return*/];
129
136
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/collections/ai-terminal-conversation.collection.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2DAA8D;AAG9D,IAAM,MAAM,GAAQ;IACnB,GAAG,EAAE;QACJ,IAAI,EAAE,MAAM;QACZ,QAAQ,EAAE,IAAI;KACd;IACD,GAAG,EAAE;QACJ,IAAI,EAAE,MAAM;QACZ,QAAQ,EAAE,IAAI;KACd;IACD,SAAS,EAAE;QACV,IAAI,EAAE,IAAI;QACV,QAAQ,EAAE,IAAI;KACd;IACD,SAAS,EAAE;QACV,IAAI,EAAE,IAAI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AC,WAAW,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,SAAS,EAAE,CAAC,CAAC,EAAE,CAAC,EAAA;;gBAA1E,SAA0E,CAAC;gBAC3E,qBAAM,+BAAuB,CAAC,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,SAAS,EAAE,CAAC,CAAC,EAAE,CAAC,EAAA;;gBAAvE,SAAuE,CAAC;gBACxE,qBAAM,+BAAuB,CAAC,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,SAAS,EAAE,CAAC,CAAC,EAAE,CAAC,EAAA;;gBAAvE,SAAuE,CAAC;;;;KACxE,EAAE,IAAI,CAAC,CAAC","file":"ai-terminal-conversation.collection.js","sourcesContent":["import { MongoManagerModel } from '../managers/mongo.manager';\nimport { AiTerminalConversationModel } from '../models/ai-terminal-conversation.model';\n\nconst schema: any = {\n\t_id: {\n\t\ttype: String,\n\t\toptional: true\n\t},\n\t__v: {\n\t\ttype: Number,\n\t\toptional: true\n\t},\n\tcreatedAt: {\n\t\ttype: Date,\n\t\toptional: true\n\t},\n\tupdatedAt: {\n\t\ttype: Date,\n\t\toptional: true\n\t},\n\tid_client: {\n\t\ttype: String,\n\t\toptional: true\n\t},\n\tid_app: {\n\t\ttype: String,\n\t\toptional: true\n\t},\n\ttitle: {\n\t\ttype: String,\n\t\toptional: true\n\t},\n\tmode: {\n\t\ttype: String,\n\t\toptional: true\n\t},\n\tbranch_enabled: {\n\t\ttype: Boolean,\n\t\toptional: true\n\t},\n\tbranch_name: {\n\t\ttype: String,\n\t\toptional: true\n\t},\n\tstatus: {\n\t\ttype: String,\n\t\toptional: true\n\t},\n\tprofile_id: {\n\t\ttype: String,\n\t\toptional: true\n\t},\n\tmetadata: {\n\t\ttype: Object,\n\t\toptional: true,\n\t\tblackbox: true\n\t},\n\tlast_message_at: {\n\t\ttype: Date,\n\t\toptional: true\n\t},\n\tlast_message_id: {\n\t\ttype: String,\n\t\toptional: true\n\t}\n};\n\nconst model = MongoManagerModel.create<AiTerminalConversationModel>({\n\tcollectionName: 'ai-terminal-conversations',\n\tschema: schema,\n\tuseVersionCollection: false,\n\tuseReportBuilder: false,\n\treportBuilderLookupTables: [],\n\ttimestamps: true,\n\tcreateLogs: false,\n\tcheckSchema: true,\n\tcollectionOptions: null\n});\n\nexport const AiTerminalConversations = model.collection_main;\n\nsetTimeout(async () => {\n\tawait AiTerminalConversations.createIndex({ id_client: 1, updatedAt: -1 });\n\tawait AiTerminalConversations.createIndex({ id_app: 1, updatedAt: -1 });\n\tawait AiTerminalConversations.createIndex({ status: 1, updatedAt: -1 });\n}, 5000);\n"]}
1
+ {"version":3,"sources":["../../src/collections/ai-terminal-conversation.collection.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2DAA8D;AAG9D,IAAM,MAAM,GAAQ;IACnB,GAAG,EAAE;QACJ,IAAI,EAAE,MAAM;QACZ,QAAQ,EAAE,IAAI;KACd;IACD,GAAG,EAAE;QACJ,IAAI,EAAE,MAAM;QACZ,QAAQ,EAAE,IAAI;KACd;IACD,SAAS,EAAE;QACV,IAAI,EAAE,IAAI;QACV,QAAQ,EAAE,IAAI;KACd;IACD,SAAS,EAAE;QACV,IAAI,EAAE,IAAI;QACV,QAAQ,EAAE,IAAI;KACd;IACD,SAAS,EAAE;QACV,IAAI,EAAE,MAAM;QACZ,QAAQ,EAAE,IAAI;KACd;IACD,OAAO,EAAE;QACR,IAAI,EAAE,MAAM;QACZ,QAAQ,EAAE,IAAI;KACd;IACD,MAAM,EAAE;QACP,IAAI,EAAE,MAAM;QACZ,QAAQ,EAAE,IAAI;KACd;IACD,KAAK,EAAE;QACN,IAAI,EAAE,MAAM;QACZ,QAAQ,EAAE,IAAI;KACd;IACD,IAAI,EAAE;QACL,IAAI,EAAE,MAAM;QACZ,QAAQ,EAAE,IAAI;KACd;IACD,cAAc,EAAE;QACf,IAAI,EAAE,OAAO;QACb,QAAQ,EAAE,IAAI;KACd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,CAAC;gBACxE,qBAAM,+BAAuB,CAAC,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,SAAS,EAAE,CAAC,CAAC,EAAE,CAAC,EAAA;;gBAAvE,SAAuE,CAAC;;;;KACxE,EAAE,IAAI,CAAC,CAAC","file":"ai-terminal-conversation.collection.js","sourcesContent":["import { MongoManagerModel } from '../managers/mongo.manager';\nimport { AiTerminalConversationModel } from '../models/ai-terminal-conversation.model';\n\nconst schema: any = {\n\t_id: {\n\t\ttype: String,\n\t\toptional: true\n\t},\n\t__v: {\n\t\ttype: Number,\n\t\toptional: true\n\t},\n\tcreatedAt: {\n\t\ttype: Date,\n\t\toptional: true\n\t},\n\tupdatedAt: {\n\t\ttype: Date,\n\t\toptional: true\n\t},\n\tid_client: {\n\t\ttype: String,\n\t\toptional: true\n\t},\n\tid_user: {\n\t\ttype: String,\n\t\toptional: true\n\t},\n\tid_app: {\n\t\ttype: String,\n\t\toptional: true\n\t},\n\ttitle: {\n\t\ttype: String,\n\t\toptional: true\n\t},\n\tmode: {\n\t\ttype: String,\n\t\toptional: true\n\t},\n\tbranch_enabled: {\n\t\ttype: Boolean,\n\t\toptional: true\n\t},\n\tbranch_name: {\n\t\ttype: String,\n\t\toptional: true\n\t},\n\tstatus: {\n\t\ttype: String,\n\t\toptional: true\n\t},\n\tprofile_id: {\n\t\ttype: String,\n\t\toptional: true\n\t},\n\tmetadata: {\n\t\ttype: Object,\n\t\toptional: true,\n\t\tblackbox: true\n\t},\n\tlast_message_at: {\n\t\ttype: Date,\n\t\toptional: true\n\t},\n\tlast_message_id: {\n\t\ttype: String,\n\t\toptional: true\n\t}\n};\n\nconst model = MongoManagerModel.create<AiTerminalConversationModel>({\n\tcollectionName: 'ai-terminal-conversations',\n\tschema: schema,\n\tuseVersionCollection: false,\n\tuseReportBuilder: false,\n\treportBuilderLookupTables: [],\n\ttimestamps: true,\n\tcreateLogs: false,\n\tcheckSchema: true,\n\tcollectionOptions: null\n});\n\nexport const AiTerminalConversations = model.collection_main;\n\nsetTimeout(async () => {\n\tawait AiTerminalConversations.createIndex({ id_client: 1, updatedAt: -1 });\n\tawait AiTerminalConversations.createIndex({ id_user: 1, updatedAt: -1 });\n\tawait AiTerminalConversations.createIndex({ id_app: 1, updatedAt: -1 });\n\tawait AiTerminalConversations.createIndex({ status: 1, updatedAt: -1 });\n}, 5000);\n"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/collections/notification.collection.ts"],"names":[],"mappings":";;;AAAA,2DAAsF;AAEtF,gEAA0D;AAE1D,IAAI,MAAM,GAAQ;IACjB,GAAG,EAAE;QACJ,IAAI,EAAE,MAAM;QACZ,QAAQ,EAAE,IAAI;KACd;IACD,GAAG,EAAE;QACJ,IAAI,EAAE,MAAM;QACZ,QAAQ,EAAE,IAAI;KACd;IACD,SAAS,EAAE;QACV,IAAI,EAAE,IAAI;QACV,QAAQ,EAAE,IAAI;KACd;IACD,SAAS,EAAE;QACV,IAAI,EAAE,IAAI;QACV,QAAQ,EAAE,IAAI;KACd;IACD,IAAI,EAAE;QACL,IAAI,EAAE,MAAM;KACZ;IACD,MAAM,EAAE;QACP,IAAI,EAAE,MAAM;QACZ,QAAQ,EAAE,IAAI;QACd,QAAQ,EAAE,IAAI;KACd;CACD,CAAC;AAES,QAAA,aAAa,GAA8C,IAAI,CAAC;AAE3E,oBAAoB,EAAE,CAAC;AAEvB,SAAS,oBAAoB;IAC5B,IAAI,sCAAe,IAAI,sCAAe,CAAC,SAAS,EAAE,IAAI,iCAAiB,EAAE,CAAC;QACzE,IAAM,KAAK,GAAG,iCAAiB,CAAC,MAAM,CAAoB;YACzD,cAAc,EAAE,eAAe;YAC/B,MAAM,EAAE,MAAM;YACd,oBAAoB,EAAE,KAAK;YAC3B,gBAAgB,EAAE,KAAK;YACvB,yBAAyB,EAAE,EAAE;YAC7B,UAAU,EAAE,IAAI;YAChB,UAAU,EAAE,KAAK;YACjB,WAAW,EAAE,IAAI;YACjB,iBAAiB,EAAE,IAAI;SACvB,CAAC,CAAC;QACH,qBAAa,GAAG,KAAK,CAAC,eAAe,CAAC;QACtC,qBAAa,CAAC,WAAW,CAAC,EAAC,IAAI,EAAE,CAAC,EAAC,EAAE,EAAC,MAAM,EAAE,IAAI,EAAC,CAAC,CAAC;IACtD,CAAC;SACI,CAAC;QACL,YAAY,CAAC;YACZ,oBAAoB,EAAE,CAAC;QACxB,CAAC,CAAC,CAAC;IACJ,CAAC;AACF,CAAC","file":"notification.collection.js","sourcesContent":["import { MongoManagerCollection, MongoManagerModel } from '../managers/mongo.manager';\nimport { NotificationModel } from '../models/notification.model';\nimport { ResolveIOServer } from '../resolveio-server-app';\n\nlet schema: any = {\n\t_id: {\n\t\ttype: String,\n\t\toptional: true\n\t},\n\t__v: {\n\t\ttype: Number,\n\t\toptional: true\n\t},\n\tupdatedAt: {\n\t\ttype: Date,\n\t\toptional: true\n\t},\n\tcreatedAt: {\n\t\ttype: Date,\n\t\toptional: true\n\t},\n\tname: {\n\t\ttype: String\n\t},\n\tconfig: {\n\t\ttype: Object,\n\t\tblackbox: true,\n\t\toptional: true\n\t}\n};\n\nexport let Notifications: MongoManagerCollection<NotificationModel> = null;\n\ninitializeCollection();\n\nfunction initializeCollection() {\n\tif (ResolveIOServer && ResolveIOServer.getMainDB() && MongoManagerModel) {\n\t\tconst model = MongoManagerModel.create<NotificationModel>({\n\t\t\tcollectionName: 'notifications',\n\t\t\tschema: schema,\n\t\t\tuseVersionCollection: false,\n\t\t\tuseReportBuilder: false,\n\t\t\treportBuilderLookupTables: [],\n\t\t\ttimestamps: true,\n\t\t\tcreateLogs: false,\n\t\t\tcheckSchema: true,\n\t\t\tcollectionOptions: null\n\t\t});\n\t\tNotifications = model.collection_main;\n\t\tNotifications.createIndex({name: 1}, {unique: true});\n\t}\n\telse {\n\t\tsetImmediate(() => {\n\t\t\tinitializeCollection();\n\t\t});\n\t}\n}"]}
1
+ {"version":3,"sources":["../../src/collections/notification.collection.ts"],"names":[],"mappings":";;;AAAA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["import { MongoManagerCollection, MongoManagerModel } from '../managers/mongo.manager';\nimport { NotificationModel } from '../models/notification.model';\nimport { ResolveIOServer } from '../resolveio-server-app';\n\nlet schema: any = {\n\t_id: {\n\t\ttype: String,\n\t\toptional: true\n\t},\n\t__v: {\n\t\ttype: Number,\n\t\toptional: true\n\t},\n\tupdatedAt: {\n\t\ttype: Date,\n\t\toptional: true\n\t},\n\tcreatedAt: {\n\t\ttype: Date,\n\t\toptional: true\n\t},\n\tname: {\n\t\ttype: String\n\t},\n\tconfig: {\n\t\ttype: Object,\n\t\tblackbox: true,\n\t\toptional: true\n\t}\n};\n\nexport let Notifications: MongoManagerCollection<NotificationModel> = null;\n\ninitializeCollection();\n\nfunction initializeCollection() {\n\tif (ResolveIOServer && ResolveIOServer.getMainDB() && MongoManagerModel) {\n\t\tconst model = MongoManagerModel.create<NotificationModel>({\n\t\t\tcollectionName: 'notifications',\n\t\t\tschema: schema,\n\t\t\tuseVersionCollection: false,\n\t\t\tuseReportBuilder: false,\n\t\t\treportBuilderLookupTables: [],\n\t\t\ttimestamps: true,\n\t\t\tcreateLogs: false,\n\t\t\tcheckSchema: true,\n\t\t\tcollectionOptions: null\n\t\t});\n\t\tNotifications = model.collection_main;\n\t\tNotifications.createIndex({ name: 1 }, { unique: true });\n\t}\n\telse {\n\t\tsetImmediate(() => {\n\t\t\tinitializeCollection();\n\t\t});\n\t}\n}\n"]}
@@ -5,6 +5,7 @@ exports.LocalLogManager = void 0;
5
5
  local-logs.manager.ts
6
6
  ****************/
7
7
  var fs = require("fs");
8
+ var path = require("path");
8
9
  var resolveio_server_app_1 = require("../resolveio-server-app");
9
10
  var LocalLogManager = /** @class */ (function () {
10
11
  function LocalLogManager() {
@@ -15,13 +16,14 @@ var LocalLogManager = /** @class */ (function () {
15
16
  return localLogManager;
16
17
  };
17
18
  LocalLogManager.prototype.initialize = function () {
19
+ var logDir = resolveLocalLogDir();
18
20
  if (resolveio_server_app_1.ResolveIOServer.getServerConfig()['ROOT_URL'] !== 'https://resolveio.com'
19
21
  && resolveio_server_app_1.ResolveIOServer.getServerConfig()['ROOT_URL'] !== 'http://localhost:4200') {
20
- if (!fs.existsSync('/home/ubuntu/resolveio/logs')) {
21
- fs.mkdirSync('/home/ubuntu/resolveio/logs');
22
+ if (!fs.existsSync(logDir)) {
23
+ fs.mkdirSync(logDir, { recursive: true });
22
24
  }
23
25
  }
24
- this._logFilePath = '/home/ubuntu/resolveio/logs/local-logs.jsonl';
26
+ this._logFilePath = path.join(logDir, 'local-logs.jsonl');
25
27
  };
26
28
  // Internal method to append a JSON line to the file
27
29
  LocalLogManager.prototype.writeLog = function (logEntry) {
@@ -76,5 +78,12 @@ var LocalLogManager = /** @class */ (function () {
76
78
  return LocalLogManager;
77
79
  }());
78
80
  exports.LocalLogManager = LocalLogManager;
81
+ function resolveLocalLogDir() {
82
+ var overrideDir = String(process.env.RESOLVEIO_LOCAL_LOG_DIR || '').trim();
83
+ if (overrideDir) {
84
+ return overrideDir;
85
+ }
86
+ return '/home/ubuntu/resolveio/logs';
87
+ }
79
88
 
80
89
  //# sourceMappingURL=local-log.manager.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/managers/local-log.manager.ts"],"names":[],"mappings":";;;AAAA;;iBAEiB;AACjB,uBAAyB;AACzB,gEAA0D;AAgB1D;IAGC;IAAe,CAAC;IAET,sBAAM,GAAb;QACC,IAAM,eAAe,GAAG,IAAI,eAAe,EAAE,CAAC;QAC9C,eAAe,CAAC,UAAU,EAAE,CAAC;QAC7B,OAAO,eAAe,CAAC;IACxB,CAAC;IAEO,oCAAU,GAAlB;QACC,IACC,sCAAe,CAAC,eAAe,EAAE,CAAC,UAAU,CAAC,KAAK,uBAAuB;eACtE,sCAAe,CAAC,eAAe,EAAE,CAAC,UAAU,CAAC,KAAK,uBAAuB,EAC3E,CAAC;YACF,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,6BAA6B,CAAC,EAAE,CAAC;gBACnD,EAAE,CAAC,SAAS,C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AAC,IAAI,IAAI,EAAE,EAAE,iBAAiB,EAAE,6BAA6B,EAAE,GAAG,CAAC,CAAC;QAClF,CAAC;IACF,CAAC;IAED;;OAEG;IACI,qCAAW,GAAlB;QACC,IAAI,MAAM,GAAG,EAAE,CAAC;QAEhB,IAAI,CAAC;YACJ,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,YAAY,CAAC,EAAE,CAAC;gBACvC,OAAO,MAAM,CAAC;YACf,CAAC;YAED,IAAI,QAAQ,GAAG,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,YAAY,EAAE,MAAM,CAAC,CAAC;YAC1D,IAAI,QAAQ,CAAC,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;gBAClC,OAAO,MAAM,CAAC;YACf,CAAC;YAED,MAAM,GAAG,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,UAAA,CAAC,IAAI,OAAA,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAf,CAAe,CAAC,CAAC;YAE3D,yDAAyD;YACzD,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC,YAAY,EAAE,EAAE,CAAC,CAAC;QACzC,CAAC;QACD,OAAM,GAAG,EAAE,CAAC;YACX,OAAO,CAAC,KAAK,CAAC,IAAI,IAAI,EAAE,EAAE,iBAAiB,EAAE,yBAAyB,EAAE,GAAG,CAAC,CAAC;QAC9E,CAAC;QAED,OAAO,MAAM,CAAC;IACf,CAAC;IACF,sBAAC;AAAD,CAnFA,AAmFC,IAAA;AAnFY,0CAAe","file":"local-log.manager.js","sourcesContent":["/***************\nlocal-logs.manager.ts\n****************/\nimport * as fs from 'fs';\nimport { ResolveIOServer } from '../resolveio-server-app';\n\nexport type LocalLogType = 'monitor-mongo' \n\t| 'monitor-memory'\n\t| 'monitor-cpu'\n\t| 'monitor-function'\n\t| 'log'\n\t| 'log-subscription'\n\t| 'log-method-latency';\n\nexport interface LocalLogModel {\n\ttype: LocalLogType;\n\tdata: any;\n\tinstance_index?: string;\n}\n\nexport class LocalLogManager {\n\tprivate _logFilePath: string;\n\n\tconstructor() {}\n\n\tstatic create() {\n\t\tconst localLogManager = new LocalLogManager();\n\t\tlocalLogManager.initialize();\n\t\treturn localLogManager;\n\t}\n\n\tprivate initialize() {\n\t\tif (\n\t\t\tResolveIOServer.getServerConfig()['ROOT_URL'] !== 'https://resolveio.com'\n\t\t\t&& ResolveIOServer.getServerConfig()['ROOT_URL'] !== 'http://localhost:4200'\n\t\t) {\n\t\t\tif (!fs.existsSync('/home/ubuntu/resolveio/logs')) {\n\t\t\t\tfs.mkdirSync('/home/ubuntu/resolveio/logs');\n\t\t\t}\n\t\t}\n\t\t\n\t\tthis._logFilePath = '/home/ubuntu/resolveio/logs/local-logs.jsonl';\n\t}\n\n\t// Internal method to append a JSON line to the file\n\tpublic writeLog(logEntry: LocalLogModel): void {\n\t\ttry {\n\t\t\tlogEntry.instance_index = process.env.NODE_APP_INSTANCE || '';\n\n\t\t\tlet log = JSON.stringify(logEntry) + '\\n';\n\t\t\tfs.appendFileSync(this._logFilePath, log, { encoding: 'utf8' });\n\t\t}\n\t\tcatch(err) {\n\t\t\t// If there's an error writing logs, you might want to handle it or queue it\n\t\t\tconsole.error(new Date(), 'LocalLogManager', 'Failed to write log to file:', err);\n\t\t}\n\t}\n\n\tpublic writeLogs(logEntries: LocalLogModel[]): void {\n\t\tif (!logEntries || logEntries.length === 0) {\n\t\t\treturn;\n\t\t}\n\n\t\ttry {\n\t\t\t// Convert each item to a JSON string, add newline\n\t\t\tlet logs = logEntries.map(logEntry => {\n\t\t\t\tlogEntry.instance_index = process.env.NODE_APP_INSTANCE || '';\n\t\t\t\treturn JSON.stringify(logEntry);\n\t\t\t}).join('\\n') + '\\n';\n\t\t\tfs.appendFileSync(this._logFilePath, logs, { encoding: 'utf8' });\n\t\t}\n\t\tcatch (err) {\n\t\t\tconsole.error(new Date(), 'LocalLogManager', 'Failed to write logs batch:', err);\n\t\t}\n\t}\n\n\t/**\n\t * Reads all logs from disk, then empties the file.\n\t */\n\tpublic offloadLogs(): any[] {\n\t\tlet result = [];\n\n\t\ttry {\n\t\t\tif (!fs.existsSync(this._logFilePath)) {\n\t\t\t\treturn result;\n\t\t\t}\n\n\t\t\tlet fileData = fs.readFileSync(this._logFilePath, 'utf8');\n\t\t\tif (fileData.trim().length === 0) {\n\t\t\t\treturn result;\n\t\t\t}\n\n\t\t\tresult = fileData.split('\\n').filter(l => l.trim() !== '');\n\n\t\t\t// Truncate the file so we don't send logs more than once\n\t\t\tfs.writeFileSync(this._logFilePath, '');\n\t\t}\n\t\tcatch(err) {\n\t\t\tconsole.error(new Date(), 'LocalLogManager', 'Failed to offload logs:', err);\n\t\t}\n\n\t\treturn result;\n\t}\n}"]}
1
+ {"version":3,"sources":["../../src/managers/local-log.manager.ts"],"names":[],"mappings":";;;AAAA;;iBAEiB;AACjB,uBAAyB;AACzB,2BAA6B;AAC7B,gEAA0D;AAgB1D;IAGC;IAAe,CAAC;IAET,sBAAM,GAAb;QACC,IAAM,eAAe,GAAG,IAAI,eAAe,EAAE,CAAC;QAC9C,eAAe,CAAC,UAAU,EAAE,CAAC;QAC7B,OAAO,eAAe,CAAC;IACxB,CAAC;IAEO,oCAAU,GAAlB;QACC,IAAM,MAAM,GAAG,kBAAkB,EAAE,CAAC;QACpC,IACC,sCAAe,CAAC,eAAe,EAAE,CAAC,UAAU,CAAC,KAAK,uBAAuB;eACtE,sCAAe,CAAC,eAAe,EAAE,CAAC,UAAU,CAAC,KAAK,uBAAuB,EAC3E,CAAC;YACF,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC;gBAC5B,EAAE,CAAC,SAAS,CAAC,MAAM,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;YAC3C,CAAC;QACF,CAAC;QAED,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,kBAAkB,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F,CAAC;IACF,CAAC;IAED;;OAEG;IACI,qCAAW,GAAlB;QACC,IAAI,MAAM,GAAG,EAAE,CAAC;QAEhB,IAAI,CAAC;YACJ,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,YAAY,CAAC,EAAE,CAAC;gBACvC,OAAO,MAAM,CAAC;YACf,CAAC;YAED,IAAI,QAAQ,GAAG,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,YAAY,EAAE,MAAM,CAAC,CAAC;YAC1D,IAAI,QAAQ,CAAC,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;gBAClC,OAAO,MAAM,CAAC;YACf,CAAC;YAED,MAAM,GAAG,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,UAAA,CAAC,IAAI,OAAA,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAf,CAAe,CAAC,CAAC;YAE3D,yDAAyD;YACzD,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC,YAAY,EAAE,EAAE,CAAC,CAAC;QACzC,CAAC;QACD,OAAM,GAAG,EAAE,CAAC;YACX,OAAO,CAAC,KAAK,CAAC,IAAI,IAAI,EAAE,EAAE,iBAAiB,EAAE,yBAAyB,EAAE,GAAG,CAAC,CAAC;QAC9E,CAAC;QAED,OAAO,MAAM,CAAC;IACf,CAAC;IACF,sBAAC;AAAD,CApFA,AAoFC,IAAA;AApFY,0CAAe;AAsF5B,SAAS,kBAAkB;IAC1B,IAAM,WAAW,GAAG,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,uBAAuB,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;IAC7E,IAAI,WAAW,EAAE,CAAC;QACjB,OAAO,WAAW,CAAC;IACpB,CAAC;IACD,OAAO,6BAA6B,CAAC;AACtC,CAAC","file":"local-log.manager.js","sourcesContent":["/***************\nlocal-logs.manager.ts\n****************/\nimport * as fs from 'fs';\nimport * as path from 'path';\nimport { ResolveIOServer } from '../resolveio-server-app';\n\nexport type LocalLogType = 'monitor-mongo' \n\t| 'monitor-memory'\n\t| 'monitor-cpu'\n\t| 'monitor-function'\n\t| 'log'\n\t| 'log-subscription'\n\t| 'log-method-latency';\n\nexport interface LocalLogModel {\n\ttype: LocalLogType;\n\tdata: any;\n\tinstance_index?: string;\n}\n\nexport class LocalLogManager {\n\tprivate _logFilePath: string;\n\n\tconstructor() {}\n\n\tstatic create() {\n\t\tconst localLogManager = new LocalLogManager();\n\t\tlocalLogManager.initialize();\n\t\treturn localLogManager;\n\t}\n\n\tprivate initialize() {\n\t\tconst logDir = resolveLocalLogDir();\n\t\tif (\n\t\t\tResolveIOServer.getServerConfig()['ROOT_URL'] !== 'https://resolveio.com'\n\t\t\t&& ResolveIOServer.getServerConfig()['ROOT_URL'] !== 'http://localhost:4200'\n\t\t) {\n\t\t\tif (!fs.existsSync(logDir)) {\n\t\t\t\tfs.mkdirSync(logDir, { recursive: true });\n\t\t\t}\n\t\t}\n\t\t\n\t\tthis._logFilePath = path.join(logDir, 'local-logs.jsonl');\n\t}\n\n\t// Internal method to append a JSON line to the file\n\tpublic writeLog(logEntry: LocalLogModel): void {\n\t\ttry {\n\t\t\tlogEntry.instance_index = process.env.NODE_APP_INSTANCE || '';\n\n\t\t\tlet log = JSON.stringify(logEntry) + '\\n';\n\t\t\tfs.appendFileSync(this._logFilePath, log, { encoding: 'utf8' });\n\t\t}\n\t\tcatch(err) {\n\t\t\t// If there's an error writing logs, you might want to handle it or queue it\n\t\t\tconsole.error(new Date(), 'LocalLogManager', 'Failed to write log to file:', err);\n\t\t}\n\t}\n\n\tpublic writeLogs(logEntries: LocalLogModel[]): void {\n\t\tif (!logEntries || logEntries.length === 0) {\n\t\t\treturn;\n\t\t}\n\n\t\ttry {\n\t\t\t// Convert each item to a JSON string, add newline\n\t\t\tlet logs = logEntries.map(logEntry => {\n\t\t\t\tlogEntry.instance_index = process.env.NODE_APP_INSTANCE || '';\n\t\t\t\treturn JSON.stringify(logEntry);\n\t\t\t}).join('\\n') + '\\n';\n\t\t\tfs.appendFileSync(this._logFilePath, logs, { encoding: 'utf8' });\n\t\t}\n\t\tcatch (err) {\n\t\t\tconsole.error(new Date(), 'LocalLogManager', 'Failed to write logs batch:', err);\n\t\t}\n\t}\n\n\t/**\n\t * Reads all logs from disk, then empties the file.\n\t */\n\tpublic offloadLogs(): any[] {\n\t\tlet result = [];\n\n\t\ttry {\n\t\t\tif (!fs.existsSync(this._logFilePath)) {\n\t\t\t\treturn result;\n\t\t\t}\n\n\t\t\tlet fileData = fs.readFileSync(this._logFilePath, 'utf8');\n\t\t\tif (fileData.trim().length === 0) {\n\t\t\t\treturn result;\n\t\t\t}\n\n\t\t\tresult = fileData.split('\\n').filter(l => l.trim() !== '');\n\n\t\t\t// Truncate the file so we don't send logs more than once\n\t\t\tfs.writeFileSync(this._logFilePath, '');\n\t\t}\n\t\tcatch(err) {\n\t\t\tconsole.error(new Date(), 'LocalLogManager', 'Failed to offload logs:', err);\n\t\t}\n\n\t\treturn result;\n\t}\n}\n\nfunction resolveLocalLogDir(): string {\n\tconst overrideDir = String(process.env.RESOLVEIO_LOCAL_LOG_DIR || '').trim();\n\tif (overrideDir) {\n\t\treturn overrideDir;\n\t}\n\treturn '/home/ubuntu/resolveio/logs';\n}\n"]}
@@ -445,6 +445,7 @@ var AI_ASSISTANT_COLLECTION_GENERIC_TOKENS = new Set([
445
445
  'list',
446
446
  'show'
447
447
  ]);
448
+ var AI_ASSISTANT_INVOICE_PERMISSION_PATTERN = /invoice/i;
448
449
  var AI_ASSISTANT_FIELD_TOKEN_SYNONYMS = {
449
450
  volume: ['quantity', 'qty', 'amount', 'gallons', 'gallon', 'liters', 'liter', 'litre'],
450
451
  quantity: ['volume', 'qty', 'amount', 'gallons', 'gallon'],
@@ -912,14 +913,20 @@ function loadAiTerminalMethods(methodManager) {
912
913
  }),
913
914
  function: function (payload) {
914
915
  return __awaiter(this, void 0, void 0, function () {
915
- var now, doc, result;
916
+ var idUser, now, doc, result;
916
917
  var _a;
917
918
  return __generator(this, function (_b) {
918
919
  switch (_b.label) {
919
920
  case 0:
921
+ idUser = normalizeOptionalString((this === null || this === void 0 ? void 0 : this.id_user) || '');
922
+ if (!idUser) {
923
+ throw new Error('Unauthorized.');
924
+ }
920
925
  now = new Date();
921
- _a = {};
922
- return [4 /*yield*/, resolveClientIdFromConfig(payload.id_client, this === null || this === void 0 ? void 0 : this.id_user)];
926
+ _a = {
927
+ id_user: idUser
928
+ };
929
+ return [4 /*yield*/, resolveClientIdFromConfig(payload.id_client, idUser)];
923
930
  case 1:
924
931
  doc = (_a.id_client = _b.sent(),
925
932
  _a.id_app = normalizeOptionalString(payload.id_app),
@@ -956,10 +963,14 @@ function loadAiTerminalMethods(methodManager) {
956
963
  }),
957
964
  function: function (id_conversation, patch) {
958
965
  return __awaiter(this, void 0, void 0, function () {
959
- var update;
966
+ var idUser, update;
960
967
  return __generator(this, function (_a) {
961
968
  switch (_a.label) {
962
969
  case 0:
970
+ idUser = normalizeOptionalString((this === null || this === void 0 ? void 0 : this.id_user) || '');
971
+ if (!idUser) {
972
+ throw new Error('Unauthorized.');
973
+ }
963
974
  update = {
964
975
  updatedAt: new Date()
965
976
  };
@@ -981,7 +992,7 @@ function loadAiTerminalMethods(methodManager) {
981
992
  if (patch.metadata !== undefined) {
982
993
  update.metadata = patch.metadata || {};
983
994
  }
984
- return [4 /*yield*/, ai_terminal_conversation_collection_1.AiTerminalConversations.updateOne({ _id: id_conversation }, { $set: update })];
995
+ return [4 /*yield*/, ai_terminal_conversation_collection_1.AiTerminalConversations.updateOne({ _id: id_conversation, id_user: idUser }, { $set: update })];
985
996
  case 1:
986
997
  _a.sent();
987
998
  return [2 /*return*/, { id_conversation: id_conversation }];
@@ -998,13 +1009,25 @@ function loadAiTerminalMethods(methodManager) {
998
1009
  }),
999
1010
  function: function (id_conversation) {
1000
1011
  return __awaiter(this, void 0, void 0, function () {
1012
+ var idUser, conversation;
1001
1013
  return __generator(this, function (_a) {
1002
1014
  switch (_a.label) {
1003
- case 0: return [4 /*yield*/, ai_terminal_message_collection_1.AiTerminalMessages.deleteMany({ id_conversation: id_conversation })];
1015
+ case 0:
1016
+ idUser = normalizeOptionalString((this === null || this === void 0 ? void 0 : this.id_user) || '');
1017
+ if (!idUser) {
1018
+ throw new Error('Unauthorized.');
1019
+ }
1020
+ return [4 /*yield*/, ai_terminal_conversation_collection_1.AiTerminalConversations.findById(id_conversation)];
1004
1021
  case 1:
1005
- _a.sent();
1006
- return [4 /*yield*/, ai_terminal_conversation_collection_1.AiTerminalConversations.deleteOne({ _id: id_conversation })];
1022
+ conversation = _a.sent();
1023
+ if (!conversation || normalizeOptionalString(conversation.id_user) !== idUser) {
1024
+ throw new Error('Conversation not found.');
1025
+ }
1026
+ return [4 /*yield*/, ai_terminal_message_collection_1.AiTerminalMessages.deleteMany({ id_conversation: id_conversation })];
1007
1027
  case 2:
1028
+ _a.sent();
1029
+ return [4 /*yield*/, ai_terminal_conversation_collection_1.AiTerminalConversations.deleteOne({ _id: id_conversation, id_user: idUser })];
1030
+ case 3:
1008
1031
  _a.sent();
1009
1032
  return [2 /*return*/, { id_conversation: id_conversation }];
1010
1033
  }
@@ -1033,10 +1056,20 @@ function loadAiTerminalMethods(methodManager) {
1033
1056
  }),
1034
1057
  function: function (id_conversation, file_name, content_base64, size, content_type) {
1035
1058
  return __awaiter(this, void 0, void 0, function () {
1036
- var limits, safeName, uploadRoot, targetDir, targetPath, dataBuffer, data;
1059
+ var idUser, conversation, limits, safeName, uploadRoot, targetDir, targetPath, dataBuffer, data;
1037
1060
  return __generator(this, function (_a) {
1038
1061
  switch (_a.label) {
1039
1062
  case 0:
1063
+ idUser = normalizeOptionalString((this === null || this === void 0 ? void 0 : this.id_user) || '');
1064
+ if (!idUser) {
1065
+ throw new Error('Unauthorized.');
1066
+ }
1067
+ return [4 /*yield*/, ai_terminal_conversation_collection_1.AiTerminalConversations.findById(id_conversation)];
1068
+ case 1:
1069
+ conversation = _a.sent();
1070
+ if (!conversation || normalizeOptionalString(conversation.id_user) !== idUser) {
1071
+ throw new Error('Conversation not found.');
1072
+ }
1040
1073
  limits = resolveUploadLimits();
1041
1074
  if (size > limits.maxFileBytes) {
1042
1075
  throw new Error("File exceeds ".concat(limits.maxFileMb, "MB limit."));
@@ -1045,7 +1078,7 @@ function loadAiTerminalMethods(methodManager) {
1045
1078
  uploadRoot = resolveUploadRoot();
1046
1079
  targetDir = path.join(uploadRoot, id_conversation);
1047
1080
  return [4 /*yield*/, fs_1.promises.mkdir(targetDir, { recursive: true })];
1048
- case 1:
1081
+ case 2:
1049
1082
  _a.sent();
1050
1083
  targetPath = path.join(targetDir, safeName);
1051
1084
  dataBuffer = Buffer.from(content_base64, 'base64');
@@ -1056,7 +1089,7 @@ function loadAiTerminalMethods(methodManager) {
1056
1089
  }
1057
1090
  }
1058
1091
  return [4 /*yield*/, fs_1.promises.writeFile(targetPath, data)];
1059
- case 2:
1092
+ case 3:
1060
1093
  _a.sent();
1061
1094
  return [2 /*return*/, {
1062
1095
  id_file: (0, common_1.objectIdHexString)(),
@@ -1264,6 +1297,9 @@ function executeAiTerminalRun(payload, context) {
1264
1297
  if (!message) {
1265
1298
  throw new Error('Message is required.');
1266
1299
  }
1300
+ if (!(context === null || context === void 0 ? void 0 : context.id_user)) {
1301
+ throw new Error('Unauthorized.');
1302
+ }
1267
1303
  requestId = normalizeOptionalString(input.request_id);
1268
1304
  identityGuardrail = evaluateAssistantIdentityDisclosureGuardrail(message);
1269
1305
  if (!(identityGuardrail === null || identityGuardrail === void 0 ? void 0 : identityGuardrail.blocked)) return [3 /*break*/, 5];
@@ -1718,7 +1754,7 @@ function executeAiAssistantCodexRun(payload, context) {
1718
1754
  insertResult = _d.sent();
1719
1755
  assistantMessageId = (insertResult === null || insertResult === void 0 ? void 0 : insertResult._id) || (insertResult === null || insertResult === void 0 ? void 0 : insertResult.insertedId);
1720
1756
  enqueueAssistantCodexRun(function () { return __awaiter(_this, void 0, void 0, function () {
1721
- var runStart, steps, recordStep, progressTracker, streamProgress, assistantContent, toolResult, assistantDebug, directiveSource, requestClassification, dataQuestion, lastDirective, heuristicDirectivePrecomputed, usedDeterministicHeuristicFastPath, requestedTimeGrain, requestedBreakdownDimensions, enforceDatedDirective, enforceGroupedDirective, datedDirectiveRetryUsed, datedDirectiveResolved, toolResponseDebug, toolError, termHints, collectionHints, fieldHints, methodHints, publicationHints, collectionTokenization, collectionRanking, collectionSelection, collectionOverride, collectionNames, plannerEnabled, plannerUsed, plannerSkipReason, plannerOutput, plannerRaw, timingBreakdown, codexUsage, accumulateCodexUsage, contextRoute, contextMode, hintSeed, termExpansion, hintText, baseTokens, expandedTokens, baseWeights, expandedWeights, dbName, db, surfaceHints, _a, allowedRoutes, rankedAllowedRoutes, routeHints, rankedCollectionHints, rankedCollections, hintCollections, assistantContext, hasDeterministicHeuristicFastPath, prompt_1, workspaceRoot, codexConfig, runOptions, plannerRunOptions, shouldRunPlanner, plannerPrompt, plannerStart, _b, preferListDirective, directiveStyleHint, directivePromptMode, responseText, directiveText, directive, heuristicDirectiveFastPath, directivePrompt, directiveStart, forcedDirective, _c, initialStart, extractedDirective, error_2, directivePrompt, forcedStart, forcedDirective, _d, strictDirectivePrompt, strictStart, strictDirectiveText, strictDirective, strictDirectiveIsDated, shouldUseStrictDirective, _e, guardDirectivePrompt, guardStart, guardDirectiveText, guardDirective, _f, groupedDirectivePrompt, groupedStart, groupedDirectiveText, groupedDirective, _g, heuristicDirective, requestedCollection, allowCollectionOverride, cleanedResponseText, denyInvoiceDataByIntent, effectiveDirective, toolRequest, toolStart, toolResponse, _h, toolPayload, skipFollowupCodex, followupPrompt, followupStart, followupText, _j, error_3, error_4, finishedAt, finalNow, finishedAt, codexMs, draftingMs, finalMetadata, finalUsage, usageClientId, usageError_1, finalAssistantDoc, setPayload;
1757
+ var runStart, steps, recordStep, progressTracker, streamProgress, assistantContent, toolResult, assistantDebug, directiveSource, requestClassification, dataQuestion, lastDirective, heuristicDirectivePrecomputed, usedDeterministicHeuristicFastPath, requestedTimeGrain, requestedBreakdownDimensions, enforceDatedDirective, enforceGroupedDirective, datedDirectiveRetryUsed, datedDirectiveResolved, toolResponseDebug, toolError, termHints, collectionHints, fieldHints, methodHints, publicationHints, collectionTokenization, collectionRanking, collectionSelection, collectionOverride, collectionNames, plannerEnabled, plannerUsed, plannerSkipReason, plannerOutput, plannerRaw, timingBreakdown, codexUsage, accumulateCodexUsage, contextRoute, contextMode, hintSeed, termExpansion, hintText, baseTokens, expandedTokens, baseWeights, expandedWeights, dbName, db, surfaceHints, _a, allowedRoutes, rankedAllowedRoutes, routeHints, rankedCollectionHints, rankedCollections, hintCollections, assistantContext, hasDeterministicHeuristicFastPath, prompt_1, workspaceRoot, codexConfig, runOptions, plannerRunOptions, shouldRunPlanner, plannerPrompt, plannerStart, _b, preferListDirective, directiveStyleHint, directivePromptMode, responseText, directiveText, directive, heuristicDirectiveFastPath, directivePrompt, directiveStart, forcedDirective, _c, initialStart, extractedDirective, error_2, directivePrompt, forcedStart, forcedDirective, _d, strictDirectivePrompt, strictStart, strictDirectiveText, strictDirective, strictDirectiveIsDated, shouldUseStrictDirective, _e, guardDirectivePrompt, guardStart, guardDirectiveText, guardDirective, _f, groupedDirectivePrompt, groupedStart, groupedDirectiveText, groupedDirective, _g, heuristicDirective, requestedCollection, allowCollectionOverride, cleanedResponseText, deniedModuleByIntent, permissionLabel, effectiveDirective, toolRequest, toolStart, toolResponse, _h, toolPayload, skipFollowupCodex, followupPrompt, followupStart, followupText, _j, error_3, error_4, finishedAt, finalNow, finishedAt, codexMs, draftingMs, finalMetadata, finalUsage, usageClientId, usageError_1, finalAssistantDoc, setPayload;
1722
1758
  var _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12;
1723
1759
  return __generator(this, function (_13) {
1724
1760
  switch (_13.label) {
@@ -2329,16 +2365,18 @@ function executeAiAssistantCodexRun(payload, context) {
2329
2365
  if (cleanedResponseText) {
2330
2366
  assistantContent = sanitizeAssistantResponse(cleanedResponseText);
2331
2367
  }
2332
- denyInvoiceDataByIntent = dataQuestion
2333
- && !isSuperAdmin
2334
- && !hasInvoiceAccess
2335
- && assistantMessageRequestsInvoiceData(message);
2336
- if (!denyInvoiceDataByIntent) return [3 /*break*/, 38];
2368
+ deniedModuleByIntent = resolveAssistantIntentDeniedModule({
2369
+ user: user,
2370
+ isSuperAdmin: isSuperAdmin,
2371
+ message: message
2372
+ });
2373
+ if (!deniedModuleByIntent) return [3 /*break*/, 38];
2374
+ permissionLabel = formatAssistantModulePermissionLabel(deniedModuleByIntent);
2337
2375
  progressTracker.push('Grabbing Data');
2338
2376
  recordStep('Grabbing Data: denied', {
2339
- reason: 'invoice_permission_required'
2377
+ reason: "".concat(deniedModuleByIntent, "_permission_required")
2340
2378
  });
2341
- assistantContent = 'I couldn\'t run the data query because this account does not have permission for that dataset.';
2379
+ assistantContent = "I couldn't run that request because this account does not have ".concat(permissionLabel, " permission.");
2342
2380
  toolError = new Error('AI assistant report builder bridge: Access denied.');
2343
2381
  return [3 /*break*/, 52];
2344
2382
  case 38:
@@ -9682,7 +9720,7 @@ function isDisplayObjectLike(value) {
9682
9720
  }
9683
9721
  function ensureAssistantReadAccess(context, permissionView, collection) {
9684
9722
  return __awaiter(this, void 0, void 0, function () {
9685
- var idUser, user, isSuperAdmin, canViewDebug, normalizedCollection, normalizedPermission, requiresInvoiceAccess, hasInvoiceAccess, hasViewAccess;
9723
+ var idUser, user, isSuperAdmin, canViewDebug, normalizedCollection, normalizedPermission, permissionModule, collectionModule, requestedModule, requiresInvoiceAccess, hasInvoiceAccess, hasViewAccess, hasModuleAccess;
9686
9724
  var _a;
9687
9725
  return __generator(this, function (_b) {
9688
9726
  switch (_b.label) {
@@ -9707,11 +9745,17 @@ function ensureAssistantReadAccess(context, permissionView, collection) {
9707
9745
  if (!normalizedPermission) {
9708
9746
  throw new Error('AI assistant report builder bridge: Permission scope required.');
9709
9747
  }
9748
+ permissionModule = resolveAssistantPrimaryModuleFromText(normalizedPermission);
9749
+ collectionModule = permissionModule ? null : resolveAssistantPrimaryModuleFromText(normalizedCollection);
9750
+ requestedModule = permissionModule || collectionModule;
9710
9751
  requiresInvoiceAccess = (normalizedCollection ? requiresInvoicePermission(normalizedCollection) : false)
9711
- || /invoice/i.test(normalizedPermission);
9752
+ || AI_ASSISTANT_INVOICE_PERMISSION_PATTERN.test(normalizedPermission);
9712
9753
  hasInvoiceAccess = requiresInvoiceAccess && userHasInvoiceAccess(user);
9713
9754
  hasViewAccess = userHasViewPermission(user, normalizedPermission);
9714
- if (!hasViewAccess && !hasInvoiceAccess) {
9755
+ hasModuleAccess = requestedModule
9756
+ ? userHasAssistantChangeModuleAccess(user, requestedModule)
9757
+ : false;
9758
+ if (!hasViewAccess && !hasInvoiceAccess && !hasModuleAccess) {
9715
9759
  throw new Error('AI assistant report builder bridge: Access denied.');
9716
9760
  }
9717
9761
  if (requiresInvoiceAccess && !hasInvoiceAccess) {
@@ -16480,7 +16524,7 @@ function collectUserViewPermissions(user) {
16480
16524
  return collected;
16481
16525
  }
16482
16526
  function userHasViewTokenPermission(user, tokenRegex) {
16483
- var _a, _b;
16527
+ var _a;
16484
16528
  if (!user || !tokenRegex) {
16485
16529
  return false;
16486
16530
  }
@@ -16488,14 +16532,10 @@ function userHasViewTokenPermission(user, tokenRegex) {
16488
16532
  return true;
16489
16533
  }
16490
16534
  var permissions = collectUserViewPermissions(user);
16491
- if (permissions.some(function (view) { return tokenRegex.test(view); })) {
16492
- return true;
16493
- }
16494
- var groups = Array.isArray((_b = user.roles) === null || _b === void 0 ? void 0 : _b.groups) ? user.roles.groups : [];
16495
- return groups.some(function (group) { return tokenRegex.test(normalizeOptionalString(group === null || group === void 0 ? void 0 : group.name)); });
16535
+ return permissions.some(function (view) { return tokenRegex.test(view); });
16496
16536
  }
16497
16537
  function userHasInvoiceAccess(user) {
16498
- return userHasViewTokenPermission(user, /invoice/i);
16538
+ return userHasViewTokenPermission(user, AI_ASSISTANT_INVOICE_PERMISSION_PATTERN);
16499
16539
  }
16500
16540
  function resolveAssistantUserAccessTier(user) {
16501
16541
  var _a, _b;
@@ -16510,14 +16550,29 @@ function requiresInvoicePermission(collection) {
16510
16550
  if (!normalized) {
16511
16551
  return false;
16512
16552
  }
16513
- return normalized.includes('invoice');
16553
+ return AI_ASSISTANT_INVOICE_PERMISSION_PATTERN.test(normalized);
16514
16554
  }
16515
- function assistantMessageRequestsInvoiceData(message) {
16516
- var normalized = normalizeOptionalString(message).toLowerCase();
16517
- if (!normalized) {
16518
- return false;
16555
+ function resolveAssistantPrimaryModuleFromText(text) {
16556
+ var modules = resolveAssistantChangeModulesFromText(text)
16557
+ .filter(function (module) { return module !== 'general' && module !== 'internal'; });
16558
+ return modules.length ? modules[0] : null;
16559
+ }
16560
+ function formatAssistantModulePermissionLabel(module) {
16561
+ var normalized = normalizeOptionalString(module).replace(/[_-]+/g, ' ').trim();
16562
+ return normalized || 'module';
16563
+ }
16564
+ function resolveAssistantIntentDeniedModule(params) {
16565
+ if (!(params === null || params === void 0 ? void 0 : params.user) || (params === null || params === void 0 ? void 0 : params.isSuperAdmin)) {
16566
+ return null;
16567
+ }
16568
+ var requestedModule = resolveAssistantPrimaryModuleFromText((params === null || params === void 0 ? void 0 : params.message) || '');
16569
+ if (!requestedModule) {
16570
+ return null;
16571
+ }
16572
+ if (userHasAssistantChangeModuleAccess(params.user, requestedModule)) {
16573
+ return null;
16519
16574
  }
16520
- return /\binvoices?\b/.test(normalized);
16575
+ return requestedModule;
16521
16576
  }
16522
16577
  function redactSensitiveFields(value) {
16523
16578
  if (Array.isArray(value)) {
@@ -18728,7 +18783,7 @@ function userHasAssistantChangeModuleAccess(user, module) {
18728
18783
  case 'delivery':
18729
18784
  return userHasViewTokenPermission(user, /delivery|route|dispatch|work[-_/ ]?order|bol|pso|sales[-_/ ]?order|truck[-_/ ]?treat(?:ing)?|treater|specialty|batch[-_/ ]?(?:treat(?:ing)?|job)|continuous|ats|automated[-_/ ]?treatment[-_/ ]?system|isotank|chemical[-_/ ]?trailer|vac[-_/ ]?truck|asset|treatment[-_/ ]?plan|treatments?/i);
18730
18785
  case 'blend':
18731
- return userHasViewTokenPermission(user, /blend|chemical|mix/i);
18786
+ return userHasViewTokenPermission(user, /blend|mix/i);
18732
18787
  case 'chemical':
18733
18788
  return userHasViewTokenPermission(user, /chemical|blend|product|item|inventory/i);
18734
18789
  case 'job':
@@ -20316,25 +20371,36 @@ function resolveClientIdFromConfig(explicit, contextUserId) {
20316
20371
  }
20317
20372
  function ensureConversation(input, mode, contextUserId) {
20318
20373
  return __awaiter(this, void 0, void 0, function () {
20319
- var idConversation, existing, now, resolvedClientId, doc, result;
20374
+ var idUser, idConversation, existing, existingUserId, now, resolvedClientId, doc, result;
20320
20375
  return __generator(this, function (_a) {
20321
20376
  switch (_a.label) {
20322
20377
  case 0:
20378
+ idUser = normalizeOptionalString(contextUserId);
20379
+ if (!idUser) {
20380
+ throw new Error('Unauthorized.');
20381
+ }
20323
20382
  idConversation = normalizeOptionalString(input.id_conversation);
20324
20383
  if (!idConversation) return [3 /*break*/, 2];
20325
20384
  return [4 /*yield*/, ai_terminal_conversation_collection_1.AiTerminalConversations.findById(idConversation)];
20326
20385
  case 1:
20327
20386
  existing = _a.sent();
20328
20387
  if (existing) {
20329
- return [2 /*return*/, existing];
20388
+ existingUserId = normalizeOptionalString(existing.id_user);
20389
+ if (existingUserId && existingUserId === idUser) {
20390
+ return [2 /*return*/, existing];
20391
+ }
20392
+ if (existingUserId && existingUserId !== idUser) {
20393
+ throw new Error('Conversation access denied.');
20394
+ }
20330
20395
  }
20331
20396
  _a.label = 2;
20332
20397
  case 2:
20333
20398
  now = new Date();
20334
- return [4 /*yield*/, resolveClientIdFromConfig(input.id_client, contextUserId)];
20399
+ return [4 /*yield*/, resolveClientIdFromConfig(input.id_client, idUser)];
20335
20400
  case 3:
20336
20401
  resolvedClientId = _a.sent();
20337
20402
  doc = {
20403
+ id_user: idUser,
20338
20404
  id_client: resolvedClientId,
20339
20405
  id_app: normalizeOptionalString(input.id_app),
20340
20406
  title: 'New Conversation',