@loxia-labs/loxia-autopilot-one 1.0.1 → 1.0.3

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 (120) hide show
  1. package/README.md +44 -54
  2. package/bin/cli.js +1 -115
  3. package/bin/loxia-terminal-v2.js +3 -0
  4. package/bin/loxia-terminal.js +3 -0
  5. package/bin/start-with-terminal.js +3 -0
  6. package/package.json +14 -15
  7. package/scripts/install-scanners.js +1 -235
  8. package/src/analyzers/CSSAnalyzer.js +1 -297
  9. package/src/analyzers/ConfigValidator.js +1 -690
  10. package/src/analyzers/ESLintAnalyzer.js +1 -320
  11. package/src/analyzers/JavaScriptAnalyzer.js +1 -261
  12. package/src/analyzers/PrettierFormatter.js +1 -247
  13. package/src/analyzers/PythonAnalyzer.js +1 -266
  14. package/src/analyzers/SecurityAnalyzer.js +1 -729
  15. package/src/analyzers/TypeScriptAnalyzer.js +1 -247
  16. package/src/analyzers/codeCloneDetector/analyzer.js +1 -344
  17. package/src/analyzers/codeCloneDetector/detector.js +1 -203
  18. package/src/analyzers/codeCloneDetector/index.js +1 -160
  19. package/src/analyzers/codeCloneDetector/parser.js +1 -199
  20. package/src/analyzers/codeCloneDetector/reporter.js +1 -148
  21. package/src/analyzers/codeCloneDetector/scanner.js +1 -59
  22. package/src/core/agentPool.js +1 -1474
  23. package/src/core/agentScheduler.js +1 -2147
  24. package/src/core/contextManager.js +1 -709
  25. package/src/core/messageProcessor.js +1 -732
  26. package/src/core/orchestrator.js +1 -548
  27. package/src/core/stateManager.js +1 -877
  28. package/src/index.js +1 -631
  29. package/src/interfaces/cli.js +1 -549
  30. package/src/interfaces/terminal/__tests__/smoke/advancedFeatures.test.js +1 -0
  31. package/src/interfaces/terminal/__tests__/smoke/agentControl.test.js +1 -0
  32. package/src/interfaces/terminal/__tests__/smoke/agents.test.js +1 -0
  33. package/src/interfaces/terminal/__tests__/smoke/components.test.js +1 -0
  34. package/src/interfaces/terminal/__tests__/smoke/connection.test.js +1 -0
  35. package/src/interfaces/terminal/__tests__/smoke/enhancements.test.js +1 -0
  36. package/src/interfaces/terminal/__tests__/smoke/imports.test.js +1 -0
  37. package/src/interfaces/terminal/__tests__/smoke/messages.test.js +1 -0
  38. package/src/interfaces/terminal/__tests__/smoke/tools.test.js +1 -0
  39. package/src/interfaces/terminal/api/apiClient.js +1 -0
  40. package/src/interfaces/terminal/api/messageRouter.js +1 -0
  41. package/src/interfaces/terminal/api/session.js +1 -0
  42. package/src/interfaces/terminal/api/websocket.js +1 -0
  43. package/src/interfaces/terminal/components/AgentCreator.js +1 -0
  44. package/src/interfaces/terminal/components/AgentEditor.js +1 -0
  45. package/src/interfaces/terminal/components/AgentSwitcher.js +1 -0
  46. package/src/interfaces/terminal/components/ErrorBoundary.js +1 -0
  47. package/src/interfaces/terminal/components/ErrorPanel.js +1 -0
  48. package/src/interfaces/terminal/components/Header.js +1 -0
  49. package/src/interfaces/terminal/components/HelpPanel.js +1 -0
  50. package/src/interfaces/terminal/components/InputBox.js +1 -0
  51. package/src/interfaces/terminal/components/Layout.js +1 -0
  52. package/src/interfaces/terminal/components/LoadingSpinner.js +1 -0
  53. package/src/interfaces/terminal/components/MessageList.js +1 -0
  54. package/src/interfaces/terminal/components/MultilineTextInput.js +1 -0
  55. package/src/interfaces/terminal/components/SearchPanel.js +1 -0
  56. package/src/interfaces/terminal/components/SettingsPanel.js +1 -0
  57. package/src/interfaces/terminal/components/StatusBar.js +1 -0
  58. package/src/interfaces/terminal/components/TextInput.js +1 -0
  59. package/src/interfaces/terminal/config/agentEditorConstants.js +1 -0
  60. package/src/interfaces/terminal/config/constants.js +1 -0
  61. package/src/interfaces/terminal/index.js +1 -0
  62. package/src/interfaces/terminal/state/useAgentControl.js +1 -0
  63. package/src/interfaces/terminal/state/useAgents.js +1 -0
  64. package/src/interfaces/terminal/state/useConnection.js +1 -0
  65. package/src/interfaces/terminal/state/useMessages.js +1 -0
  66. package/src/interfaces/terminal/state/useTools.js +1 -0
  67. package/src/interfaces/terminal/utils/debugLogger.js +1 -0
  68. package/src/interfaces/terminal/utils/settingsStorage.js +1 -0
  69. package/src/interfaces/terminal/utils/theme.js +1 -0
  70. package/src/interfaces/webServer.js +1 -2162
  71. package/src/modules/fileExplorer/controller.js +1 -280
  72. package/src/modules/fileExplorer/index.js +1 -37
  73. package/src/modules/fileExplorer/middleware.js +1 -92
  74. package/src/modules/fileExplorer/routes.js +1 -125
  75. package/src/modules/fileExplorer/types.js +1 -44
  76. package/src/services/aiService.js +1 -1232
  77. package/src/services/apiKeyManager.js +1 -164
  78. package/src/services/benchmarkService.js +1 -366
  79. package/src/services/budgetService.js +1 -539
  80. package/src/services/contextInjectionService.js +1 -247
  81. package/src/services/conversationCompactionService.js +1 -637
  82. package/src/services/errorHandler.js +1 -810
  83. package/src/services/fileAttachmentService.js +1 -544
  84. package/src/services/modelRouterService.js +1 -366
  85. package/src/services/modelsService.js +1 -322
  86. package/src/services/qualityInspector.js +1 -796
  87. package/src/services/tokenCountingService.js +1 -536
  88. package/src/tools/agentCommunicationTool.js +1 -1344
  89. package/src/tools/agentDelayTool.js +1 -485
  90. package/src/tools/asyncToolManager.js +1 -604
  91. package/src/tools/baseTool.js +1 -800
  92. package/src/tools/browserTool.js +1 -920
  93. package/src/tools/cloneDetectionTool.js +1 -621
  94. package/src/tools/dependencyResolverTool.js +1 -1215
  95. package/src/tools/fileContentReplaceTool.js +1 -875
  96. package/src/tools/fileSystemTool.js +1 -1107
  97. package/src/tools/fileTreeTool.js +1 -853
  98. package/src/tools/imageTool.js +1 -901
  99. package/src/tools/importAnalyzerTool.js +1 -1060
  100. package/src/tools/jobDoneTool.js +1 -248
  101. package/src/tools/seekTool.js +1 -956
  102. package/src/tools/staticAnalysisTool.js +1 -1778
  103. package/src/tools/taskManagerTool.js +1 -2873
  104. package/src/tools/terminalTool.js +1 -2304
  105. package/src/tools/webTool.js +1 -1430
  106. package/src/types/agent.js +1 -519
  107. package/src/types/contextReference.js +1 -972
  108. package/src/types/conversation.js +1 -730
  109. package/src/types/toolCommand.js +1 -747
  110. package/src/utilities/attachmentValidator.js +1 -292
  111. package/src/utilities/configManager.js +1 -582
  112. package/src/utilities/constants.js +1 -722
  113. package/src/utilities/directoryAccessManager.js +1 -535
  114. package/src/utilities/fileProcessor.js +1 -307
  115. package/src/utilities/logger.js +1 -436
  116. package/src/utilities/tagParser.js +1 -1246
  117. package/src/utilities/toolConstants.js +1 -317
  118. package/web-ui/build/index.html +2 -2
  119. package/web-ui/build/static/{index-Dy2bYbOa.css → index-CClD1090.css} +1 -1
  120. package/web-ui/build/static/{index-CjkkcnFA.js → index-lCBai6dX.js} +66 -67
@@ -1,730 +1 @@
1
- /**
2
- * Conversation Data Model - Type definitions and validation for conversations
3
- *
4
- * Purpose:
5
- * - Define the structure and properties of conversations
6
- * - Provide validation functions for conversation data
7
- * - Handle conversation lifecycle and state management
8
- */
9
-
10
- import { CONVERSATION_STATUS, MESSAGE_ROLES } from '../utilities/constants.js';
11
-
12
- /**
13
- * Conversation data model
14
- * @typedef {Object} Conversation
15
- * @property {string} id - Unique conversation identifier
16
- * @property {string} title - Human-readable conversation title
17
- * @property {string} agentId - ID of the associated agent
18
- * @property {string} status - Conversation status (active, archived, suspended)
19
- * @property {Message[]} messages - Array of conversation messages
20
- * @property {ConversationMetadata} metadata - Conversation metadata
21
- * @property {ConversationSettings} settings - Conversation-specific settings
22
- * @property {ConversationContext} context - Current conversation context
23
- * @property {string} createdAt - ISO timestamp of creation
24
- * @property {string} updatedAt - ISO timestamp of last update
25
- * @property {string} lastMessageAt - ISO timestamp of last message
26
- * @property {number} messageCount - Total number of messages
27
- * @property {number} tokenCount - Total tokens used in conversation
28
- * @property {number} cost - Total cost of conversation (USD)
29
- * @property {string[]} participants - List of participant IDs
30
- * @property {Object} summary - Conversation summary data
31
- */
32
-
33
- /**
34
- * Message data model
35
- * @typedef {Object} Message
36
- * @property {string} id - Unique message identifier
37
- * @property {string} conversationId - ID of parent conversation
38
- * @property {string} role - Message role (user, assistant, system)
39
- * @property {string} content - Message content
40
- * @property {string} agentId - ID of agent (for assistant messages)
41
- * @property {string} userId - ID of user (for user messages)
42
- * @property {MessageMetadata} metadata - Message metadata
43
- * @property {ContextReference[]} contextReferences - Referenced context items
44
- * @property {ToolExecution[]} toolExecutions - Tool executions in this message
45
- * @property {TokenUsage} tokenUsage - Token usage for this message
46
- * @property {string} createdAt - ISO timestamp of creation
47
- * @property {string} [editedAt] - ISO timestamp of last edit
48
- * @property {string} [parentMessageId] - ID of parent message (for edits/branches)
49
- * @property {boolean} isEdited - Whether message has been edited
50
- * @property {Object} flags - Message flags and annotations
51
- */
52
-
53
- /**
54
- * Conversation metadata
55
- * @typedef {Object} ConversationMetadata
56
- * @property {string[]} tags - Conversation tags
57
- * @property {string} category - Conversation category
58
- * @property {string} description - Conversation description
59
- * @property {boolean} isBookmarked - Whether conversation is bookmarked
60
- * @property {number} priority - Conversation priority (1-5)
61
- * @property {string} language - Primary language of conversation
62
- * @property {Object} customFields - Custom metadata fields
63
- * @property {string[]} relatedConversations - IDs of related conversations
64
- */
65
-
66
- /**
67
- * Conversation settings
68
- * @typedef {Object} ConversationSettings
69
- * @property {boolean} persistHistory - Whether to persist conversation history
70
- * @property {number} maxMessages - Maximum number of messages to keep
71
- * @property {boolean} autoSummarize - Whether to auto-generate summaries
72
- * @property {number} summarizeThreshold - Message count threshold for summarization
73
- * @property {boolean} enableContextReferences - Whether context references are enabled
74
- * @property {number} maxContextReferences - Maximum context references per message
75
- * @property {Object} notificationSettings - Notification preferences
76
- * @property {Object} privacySettings - Privacy and sharing settings
77
- */
78
-
79
- /**
80
- * Conversation context
81
- * @typedef {Object} ConversationContext
82
- * @property {string} currentTopic - Current conversation topic
83
- * @property {string[]} mentionedEntities - Entities mentioned in conversation
84
- * @property {Object} variables - Context variables and their values
85
- * @property {string[]} activeTools - Currently active/relevant tools
86
- * @property {Object} workingMemory - Short-term memory for conversation
87
- * @property {Object} preferences - User preferences relevant to conversation
88
- * @property {string} phase - Current conversation phase
89
- * @property {Object} goals - Conversation goals and objectives
90
- */
91
-
92
- /**
93
- * Message metadata
94
- * @typedef {Object} MessageMetadata
95
- * @property {string} model - AI model used (for assistant messages)
96
- * @property {number} temperature - Generation temperature used
97
- * @property {number} responseTime - Time taken to generate response (ms)
98
- * @property {string} ipAddress - IP address of sender (if applicable)
99
- * @property {string} userAgent - User agent string (if applicable)
100
- * @property {Object} modelParameters - Model-specific parameters used
101
- * @property {string} generationId - Unique generation identifier
102
- * @property {Object} annotations - Message annotations and labels
103
- */
104
-
105
- /**
106
- * Token usage information
107
- * @typedef {Object} TokenUsage
108
- * @property {number} promptTokens - Tokens used in prompt
109
- * @property {number} completionTokens - Tokens used in completion
110
- * @property {number} totalTokens - Total tokens used
111
- * @property {number} cost - Cost of token usage (USD)
112
- * @property {string} model - Model used for generation
113
- * @property {Object} breakdown - Detailed token usage breakdown
114
- */
115
-
116
- /**
117
- * Context reference in messages
118
- * @typedef {Object} ContextReference
119
- * @property {string} id - Unique reference identifier
120
- * @property {string} type - Reference type (file, component, selection, directory)
121
- * @property {string} path - Path or identifier of referenced item
122
- * @property {string} name - Human-readable name
123
- * @property {string} [content] - Referenced content (if applicable)
124
- * @property {number} [startLine] - Start line (for selections)
125
- * @property {number} [endLine] - End line (for selections)
126
- * @property {Object} metadata - Reference metadata
127
- */
128
-
129
- /**
130
- * Tool execution information
131
- * @typedef {Object} ToolExecution
132
- * @property {string} id - Unique execution identifier
133
- * @property {string} toolId - Tool identifier
134
- * @property {string} status - Execution status (pending, executing, completed, failed)
135
- * @property {Object} input - Tool input parameters
136
- * @property {Object} [output] - Tool output (if completed)
137
- * @property {string} [error] - Error message (if failed)
138
- * @property {number} executionTime - Execution time in milliseconds
139
- * @property {string} startedAt - ISO timestamp when execution started
140
- * @property {string} [completedAt] - ISO timestamp when execution completed
141
- */
142
-
143
- /**
144
- * Conversation validation functions
145
- */
146
- export class ConversationValidator {
147
- /**
148
- * Validate conversation data structure
149
- * @param {Object} conversation - Conversation data to validate
150
- * @returns {Object} Validation result
151
- */
152
- static validate(conversation) {
153
- const errors = [];
154
- const warnings = [];
155
-
156
- // Required fields
157
- if (!conversation.id || typeof conversation.id !== 'string') {
158
- errors.push('Conversation ID is required and must be a string');
159
- }
160
-
161
- if (!conversation.agentId || typeof conversation.agentId !== 'string') {
162
- errors.push('Agent ID is required and must be a string');
163
- }
164
-
165
- if (!conversation.title || typeof conversation.title !== 'string') {
166
- errors.push('Conversation title is required and must be a string');
167
- }
168
-
169
- if (conversation.title && conversation.title.length > 200) {
170
- warnings.push('Conversation title is very long (>200 characters)');
171
- }
172
-
173
- // Status validation
174
- if (conversation.status && !Object.values(CONVERSATION_STATUS).includes(conversation.status)) {
175
- errors.push(`Invalid conversation status: ${conversation.status}`);
176
- }
177
-
178
- // Messages validation
179
- if (conversation.messages && !Array.isArray(conversation.messages)) {
180
- errors.push('Messages must be an array');
181
- }
182
-
183
- if (conversation.messages) {
184
- conversation.messages.forEach((message, index) => {
185
- const messageValidation = this.validateMessage(message);
186
- messageValidation.errors.forEach(error => {
187
- errors.push(`Message ${index}: ${error}`);
188
- });
189
- messageValidation.warnings.forEach(warning => {
190
- warnings.push(`Message ${index}: ${warning}`);
191
- });
192
- });
193
- }
194
-
195
- // Numeric validations
196
- if (conversation.messageCount !== undefined && typeof conversation.messageCount !== 'number') {
197
- errors.push('Message count must be a number');
198
- }
199
-
200
- if (conversation.tokenCount !== undefined && typeof conversation.tokenCount !== 'number') {
201
- errors.push('Token count must be a number');
202
- }
203
-
204
- if (conversation.cost !== undefined && typeof conversation.cost !== 'number') {
205
- errors.push('Cost must be a number');
206
- }
207
-
208
- // Participants validation
209
- if (conversation.participants && !Array.isArray(conversation.participants)) {
210
- errors.push('Participants must be an array');
211
- }
212
-
213
- // Timestamp validation
214
- const timestampFields = ['createdAt', 'updatedAt', 'lastMessageAt'];
215
- timestampFields.forEach(field => {
216
- if (conversation[field] && !this.isValidTimestamp(conversation[field])) {
217
- errors.push(`Invalid timestamp for ${field}: ${conversation[field]}`);
218
- }
219
- });
220
-
221
- return {
222
- isValid: errors.length === 0,
223
- errors,
224
- warnings
225
- };
226
- }
227
-
228
- /**
229
- * Validate message data structure
230
- * @param {Object} message - Message data to validate
231
- * @returns {Object} Validation result
232
- */
233
- static validateMessage(message) {
234
- const errors = [];
235
- const warnings = [];
236
-
237
- // Required fields
238
- if (!message.id || typeof message.id !== 'string') {
239
- errors.push('Message ID is required and must be a string');
240
- }
241
-
242
- if (!message.conversationId || typeof message.conversationId !== 'string') {
243
- errors.push('Conversation ID is required and must be a string');
244
- }
245
-
246
- if (!message.role || typeof message.role !== 'string') {
247
- errors.push('Message role is required and must be a string');
248
- }
249
-
250
- if (message.role && !Object.values(MESSAGE_ROLES).includes(message.role)) {
251
- errors.push(`Invalid message role: ${message.role}`);
252
- }
253
-
254
- if (!message.content || typeof message.content !== 'string') {
255
- errors.push('Message content is required and must be a string');
256
- }
257
-
258
- if (message.content && message.content.length > 100000) {
259
- warnings.push('Message content is very long (>100000 characters)');
260
- }
261
-
262
- // Role-specific validations
263
- if (message.role === MESSAGE_ROLES.ASSISTANT && !message.agentId) {
264
- errors.push('Assistant messages must have an agentId');
265
- }
266
-
267
- if (message.role === MESSAGE_ROLES.USER && !message.userId) {
268
- warnings.push('User messages should have a userId');
269
- }
270
-
271
- // Context references validation
272
- if (message.contextReferences && !Array.isArray(message.contextReferences)) {
273
- errors.push('Context references must be an array');
274
- }
275
-
276
- // Tool executions validation
277
- if (message.toolExecutions && !Array.isArray(message.toolExecutions)) {
278
- errors.push('Tool executions must be an array');
279
- }
280
-
281
- // Token usage validation
282
- if (message.tokenUsage) {
283
- const tokenValidation = this.validateTokenUsage(message.tokenUsage);
284
- errors.push(...tokenValidation.errors);
285
- warnings.push(...tokenValidation.warnings);
286
- }
287
-
288
- // Timestamp validation
289
- if (message.createdAt && !this.isValidTimestamp(message.createdAt)) {
290
- errors.push(`Invalid createdAt timestamp: ${message.createdAt}`);
291
- }
292
-
293
- if (message.editedAt && !this.isValidTimestamp(message.editedAt)) {
294
- errors.push(`Invalid editedAt timestamp: ${message.editedAt}`);
295
- }
296
-
297
- return { errors, warnings };
298
- }
299
-
300
- /**
301
- * Validate token usage data
302
- * @param {Object} tokenUsage - Token usage to validate
303
- * @returns {Object} Validation result
304
- */
305
- static validateTokenUsage(tokenUsage) {
306
- const errors = [];
307
- const warnings = [];
308
-
309
- if (typeof tokenUsage.totalTokens !== 'number' || tokenUsage.totalTokens < 0) {
310
- errors.push('Total tokens must be a non-negative number');
311
- }
312
-
313
- if (tokenUsage.promptTokens !== undefined && (typeof tokenUsage.promptTokens !== 'number' || tokenUsage.promptTokens < 0)) {
314
- errors.push('Prompt tokens must be a non-negative number');
315
- }
316
-
317
- if (tokenUsage.completionTokens !== undefined && (typeof tokenUsage.completionTokens !== 'number' || tokenUsage.completionTokens < 0)) {
318
- errors.push('Completion tokens must be a non-negative number');
319
- }
320
-
321
- if (tokenUsage.cost !== undefined && (typeof tokenUsage.cost !== 'number' || tokenUsage.cost < 0)) {
322
- errors.push('Cost must be a non-negative number');
323
- }
324
-
325
- if (tokenUsage.promptTokens && tokenUsage.completionTokens) {
326
- const calculatedTotal = tokenUsage.promptTokens + tokenUsage.completionTokens;
327
- if (Math.abs(calculatedTotal - tokenUsage.totalTokens) > 1) {
328
- warnings.push('Total tokens does not match sum of prompt and completion tokens');
329
- }
330
- }
331
-
332
- return { errors, warnings };
333
- }
334
-
335
- /**
336
- * Check if a timestamp is valid ISO string
337
- * @param {string} timestamp - Timestamp to validate
338
- * @returns {boolean} True if valid
339
- */
340
- static isValidTimestamp(timestamp) {
341
- if (typeof timestamp !== 'string') return false;
342
- const date = new Date(timestamp);
343
- return date instanceof Date && !isNaN(date.getTime());
344
- }
345
- }
346
-
347
- /**
348
- * Conversation factory functions
349
- */
350
- export class ConversationFactory {
351
- /**
352
- * Create a new conversation
353
- * @param {string} agentId - Agent ID
354
- * @param {string} title - Conversation title
355
- * @param {Object} options - Additional options
356
- * @returns {Conversation} New conversation object
357
- */
358
- static create(agentId, title, options = {}) {
359
- const now = new Date().toISOString();
360
- const conversationId = this.generateConversationId();
361
-
362
- return {
363
- id: conversationId,
364
- title: title || 'New Conversation',
365
- agentId,
366
- status: CONVERSATION_STATUS.ACTIVE,
367
- messages: [],
368
- metadata: this.createDefaultMetadata(options.metadata),
369
- settings: this.createDefaultSettings(options.settings),
370
- context: this.createDefaultContext(),
371
- createdAt: now,
372
- updatedAt: now,
373
- lastMessageAt: now,
374
- messageCount: 0,
375
- tokenCount: 0,
376
- cost: 0,
377
- participants: [agentId, ...(options.participants || [])],
378
- summary: {}
379
- };
380
- }
381
-
382
- /**
383
- * Create a new message
384
- * @param {string} conversationId - Conversation ID
385
- * @param {string} role - Message role
386
- * @param {string} content - Message content
387
- * @param {Object} options - Additional options
388
- * @returns {Message} New message object
389
- */
390
- static createMessage(conversationId, role, content, options = {}) {
391
- const now = new Date().toISOString();
392
- const messageId = this.generateMessageId();
393
-
394
- return {
395
- id: messageId,
396
- conversationId,
397
- role,
398
- content,
399
- agentId: options.agentId || null,
400
- userId: options.userId || null,
401
- metadata: options.metadata || {},
402
- contextReferences: options.contextReferences || [],
403
- toolExecutions: options.toolExecutions || [],
404
- tokenUsage: options.tokenUsage || null,
405
- createdAt: now,
406
- editedAt: null,
407
- parentMessageId: options.parentMessageId || null,
408
- isEdited: false,
409
- flags: options.flags || {}
410
- };
411
- }
412
-
413
- /**
414
- * Create default conversation metadata
415
- * @param {Object} overrides - Metadata overrides
416
- * @returns {ConversationMetadata} Default metadata
417
- */
418
- static createDefaultMetadata(overrides = {}) {
419
- return {
420
- tags: [],
421
- category: 'general',
422
- description: '',
423
- isBookmarked: false,
424
- priority: 3,
425
- language: 'en',
426
- customFields: {},
427
- relatedConversations: [],
428
- ...overrides
429
- };
430
- }
431
-
432
- /**
433
- * Create default conversation settings
434
- * @param {Object} overrides - Settings overrides
435
- * @returns {ConversationSettings} Default settings
436
- */
437
- static createDefaultSettings(overrides = {}) {
438
- return {
439
- persistHistory: true,
440
- maxMessages: 1000,
441
- autoSummarize: true,
442
- summarizeThreshold: 50,
443
- enableContextReferences: true,
444
- maxContextReferences: 10,
445
- notificationSettings: {
446
- newMessage: true,
447
- agentResponse: true,
448
- toolExecution: false
449
- },
450
- privacySettings: {
451
- shareHistory: false,
452
- allowAnalytics: true
453
- },
454
- ...overrides
455
- };
456
- }
457
-
458
- /**
459
- * Create default conversation context
460
- * @returns {ConversationContext} Default context
461
- */
462
- static createDefaultContext() {
463
- return {
464
- currentTopic: null,
465
- mentionedEntities: [],
466
- variables: {},
467
- activeTools: [],
468
- workingMemory: {},
469
- preferences: {},
470
- phase: 'initial',
471
- goals: {}
472
- };
473
- }
474
-
475
- /**
476
- * Generate unique conversation ID
477
- * @returns {string} Unique conversation ID
478
- */
479
- static generateConversationId() {
480
- const timestamp = Date.now().toString(36);
481
- const random = Math.random().toString(36).substr(2, 9);
482
- return `conv_${timestamp}_${random}`;
483
- }
484
-
485
- /**
486
- * Generate unique message ID
487
- * @returns {string} Unique message ID
488
- */
489
- static generateMessageId() {
490
- const timestamp = Date.now().toString(36);
491
- const random = Math.random().toString(36).substr(2, 9);
492
- return `msg_${timestamp}_${random}`;
493
- }
494
- }
495
-
496
- /**
497
- * Conversation utility functions
498
- */
499
- export class ConversationUtils {
500
- /**
501
- * Calculate conversation statistics
502
- * @param {Conversation} conversation - Conversation to analyze
503
- * @returns {Object} Conversation statistics
504
- */
505
- static getStatistics(conversation) {
506
- const messages = conversation.messages || [];
507
- const userMessages = messages.filter(m => m.role === MESSAGE_ROLES.USER);
508
- const assistantMessages = messages.filter(m => m.role === MESSAGE_ROLES.ASSISTANT);
509
- const systemMessages = messages.filter(m => m.role === MESSAGE_ROLES.SYSTEM);
510
-
511
- const totalTokens = messages.reduce((sum, m) => sum + (m.tokenUsage?.totalTokens || 0), 0);
512
- const totalCost = messages.reduce((sum, m) => sum + (m.tokenUsage?.cost || 0), 0);
513
-
514
- const toolExecutions = messages.reduce((sum, m) => sum + (m.toolExecutions?.length || 0), 0);
515
- const contextReferences = messages.reduce((sum, m) => sum + (m.contextReferences?.length || 0), 0);
516
-
517
- return {
518
- totalMessages: messages.length,
519
- userMessages: userMessages.length,
520
- assistantMessages: assistantMessages.length,
521
- systemMessages: systemMessages.length,
522
- totalTokens,
523
- totalCost,
524
- toolExecutions,
525
- contextReferences,
526
- averageMessageLength: messages.length > 0
527
- ? messages.reduce((sum, m) => sum + m.content.length, 0) / messages.length
528
- : 0,
529
- conversationDuration: this.getConversationDuration(conversation)
530
- };
531
- }
532
-
533
- /**
534
- * Get conversation duration in milliseconds
535
- * @param {Conversation} conversation - Conversation to analyze
536
- * @returns {number} Duration in milliseconds
537
- */
538
- static getConversationDuration(conversation) {
539
- if (!conversation.messages || conversation.messages.length === 0) {
540
- return 0;
541
- }
542
-
543
- const firstMessage = conversation.messages[0];
544
- const lastMessage = conversation.messages[conversation.messages.length - 1];
545
-
546
- const startTime = new Date(firstMessage.createdAt);
547
- const endTime = new Date(lastMessage.createdAt);
548
-
549
- return endTime.getTime() - startTime.getTime();
550
- }
551
-
552
- /**
553
- * Generate conversation summary
554
- * @param {Conversation} conversation - Conversation to summarize
555
- * @returns {Object} Conversation summary
556
- */
557
- static generateSummary(conversation) {
558
- const stats = this.getStatistics(conversation);
559
- const messages = conversation.messages || [];
560
-
561
- // Extract key topics and entities
562
- const topics = this.extractTopics(messages);
563
- const entities = this.extractEntities(messages);
564
-
565
- // Get recent activity
566
- const recentMessages = messages.slice(-10);
567
- const lastActivity = conversation.lastMessageAt || conversation.updatedAt;
568
-
569
- return {
570
- title: conversation.title,
571
- messageCount: stats.totalMessages,
572
- duration: stats.conversationDuration,
573
- participants: conversation.participants.length,
574
- topics: topics.slice(0, 5), // Top 5 topics
575
- entities: entities.slice(0, 10), // Top 10 entities
576
- lastActivity,
577
- recentActivity: recentMessages.map(m => ({
578
- role: m.role,
579
- timestamp: m.createdAt,
580
- preview: m.content.substring(0, 100) + (m.content.length > 100 ? '...' : '')
581
- })),
582
- stats
583
- };
584
- }
585
-
586
- /**
587
- * Extract topics from conversation messages
588
- * @param {Message[]} messages - Messages to analyze
589
- * @returns {string[]} Extracted topics
590
- */
591
- static extractTopics(messages) {
592
- // Simple topic extraction based on keywords
593
- // In a real implementation, this would use more sophisticated NLP
594
- const topicKeywords = new Map();
595
-
596
- messages.forEach(message => {
597
- const words = message.content.toLowerCase()
598
- .split(/\s+/)
599
- .filter(word => word.length > 3 && !this.isStopWord(word));
600
-
601
- words.forEach(word => {
602
- topicKeywords.set(word, (topicKeywords.get(word) || 0) + 1);
603
- });
604
- });
605
-
606
- return Array.from(topicKeywords.entries())
607
- .sort((a, b) => b[1] - a[1])
608
- .map(([word]) => word);
609
- }
610
-
611
- /**
612
- * Extract entities from conversation messages
613
- * @param {Message[]} messages - Messages to analyze
614
- * @returns {string[]} Extracted entities
615
- */
616
- static extractEntities(messages) {
617
- // Simple entity extraction
618
- // In a real implementation, this would use NER
619
- const entities = new Set();
620
-
621
- messages.forEach(message => {
622
- // Extract capitalized words (potential proper nouns)
623
- const capitalizedWords = message.content.match(/\b[A-Z][a-z]+\b/g) || [];
624
- capitalizedWords.forEach(word => entities.add(word));
625
-
626
- // Extract file paths
627
- const filePaths = message.content.match(/\b[\w\/\-\.]+\.\w+\b/g) || [];
628
- filePaths.forEach(path => entities.add(path));
629
- });
630
-
631
- return Array.from(entities);
632
- }
633
-
634
- /**
635
- * Check if word is a stop word
636
- * @param {string} word - Word to check
637
- * @returns {boolean} True if stop word
638
- */
639
- static isStopWord(word) {
640
- const stopWords = new Set([
641
- 'the', 'and', 'or', 'but', 'in', 'on', 'at', 'to', 'for', 'of', 'with',
642
- 'by', 'from', 'up', 'about', 'into', 'through', 'during', 'before',
643
- 'after', 'above', 'below', 'over', 'under', 'again', 'further',
644
- 'then', 'once', 'here', 'there', 'when', 'where', 'why', 'how',
645
- 'all', 'any', 'both', 'each', 'few', 'more', 'most', 'other',
646
- 'some', 'such', 'only', 'own', 'same', 'so', 'than', 'too',
647
- 'very', 'can', 'will', 'just', 'should', 'now'
648
- ]);
649
-
650
- return stopWords.has(word.toLowerCase());
651
- }
652
-
653
- /**
654
- * Format conversation for export
655
- * @param {Conversation} conversation - Conversation to format
656
- * @param {string} format - Export format ('json', 'markdown', 'plain')
657
- * @returns {string} Formatted conversation
658
- */
659
- static formatForExport(conversation, format = 'json') {
660
- switch (format) {
661
- case 'markdown':
662
- return this.formatAsMarkdown(conversation);
663
- case 'plain':
664
- return this.formatAsPlainText(conversation);
665
- case 'json':
666
- default:
667
- return JSON.stringify(conversation, null, 2);
668
- }
669
- }
670
-
671
- /**
672
- * Format conversation as markdown
673
- * @param {Conversation} conversation - Conversation to format
674
- * @returns {string} Markdown formatted conversation
675
- */
676
- static formatAsMarkdown(conversation) {
677
- let markdown = `# ${conversation.title}\n\n`;
678
- markdown += `**Created:** ${new Date(conversation.createdAt).toLocaleString()}\n`;
679
- markdown += `**Agent:** ${conversation.agentId}\n`;
680
- markdown += `**Messages:** ${conversation.messageCount}\n\n`;
681
-
682
- conversation.messages.forEach(message => {
683
- const timestamp = new Date(message.createdAt).toLocaleTimeString();
684
- const role = message.role.charAt(0).toUpperCase() + message.role.slice(1);
685
-
686
- markdown += `## ${role} (${timestamp})\n\n`;
687
- markdown += `${message.content}\n\n`;
688
-
689
- if (message.contextReferences && message.contextReferences.length > 0) {
690
- markdown += `**Context References:**\n`;
691
- message.contextReferences.forEach(ref => {
692
- markdown += `- ${ref.name} (${ref.type})\n`;
693
- });
694
- markdown += '\n';
695
- }
696
- });
697
-
698
- return markdown;
699
- }
700
-
701
- /**
702
- * Format conversation as plain text
703
- * @param {Conversation} conversation - Conversation to format
704
- * @returns {string} Plain text formatted conversation
705
- */
706
- static formatAsPlainText(conversation) {
707
- let text = `Conversation: ${conversation.title}\n`;
708
- text += `Created: ${new Date(conversation.createdAt).toLocaleString()}\n`;
709
- text += `Agent: ${conversation.agentId}\n`;
710
- text += `Messages: ${conversation.messageCount}\n\n`;
711
-
712
- text += '-'.repeat(50) + '\n\n';
713
-
714
- conversation.messages.forEach(message => {
715
- const timestamp = new Date(message.createdAt).toLocaleTimeString();
716
- const role = message.role.toUpperCase();
717
-
718
- text += `[${timestamp}] ${role}:\n`;
719
- text += `${message.content}\n\n`;
720
- });
721
-
722
- return text;
723
- }
724
- }
725
-
726
- export default {
727
- ConversationValidator,
728
- ConversationFactory,
729
- ConversationUtils
730
- };
1
+ const a0_0x548405=a0_0x93ef;(function(_0x2fd3af,_0x312256){const _0x48f7b4=a0_0x93ef,_0x4daf17=_0x2fd3af();while(!![]){try{const _0x58cd4d=-parseInt(_0x48f7b4(0xe2))/0x1+parseInt(_0x48f7b4(0xa3))/0x2+parseInt(_0x48f7b4(0xbd))/0x3*(parseInt(_0x48f7b4(0xd1))/0x4)+-parseInt(_0x48f7b4(0x9f))/0x5*(parseInt(_0x48f7b4(0x92))/0x6)+-parseInt(_0x48f7b4(0xc4))/0x7*(-parseInt(_0x48f7b4(0xcc))/0x8)+parseInt(_0x48f7b4(0xbf))/0x9*(-parseInt(_0x48f7b4(0x71))/0xa)+parseInt(_0x48f7b4(0xd2))/0xb*(parseInt(_0x48f7b4(0xe6))/0xc);if(_0x58cd4d===_0x312256)break;else _0x4daf17['push'](_0x4daf17['shift']());}catch(_0x5522b2){_0x4daf17['push'](_0x4daf17['shift']());}}}(a0_0x1143,0x96e8d));import{CONVERSATION_STATUS,MESSAGE_ROLES}from'../utilities/constants.js';export class ConversationValidator{static[a0_0x548405(0xa0)](_0x167b2e){const _0x163ab2=a0_0x548405,_0xbc616e=[],_0x50327c=[];(!_0x167b2e['id']||typeof _0x167b2e['id']!==_0x163ab2(0xe8))&&_0xbc616e['push'](_0x163ab2(0x6e));(!_0x167b2e[_0x163ab2(0x76)]||typeof _0x167b2e['agentId']!==_0x163ab2(0xe8))&&_0xbc616e[_0x163ab2(0xdc)](_0x163ab2(0x99));(!_0x167b2e[_0x163ab2(0xa8)]||typeof _0x167b2e[_0x163ab2(0xa8)]!==_0x163ab2(0xe8))&&_0xbc616e['push'](_0x163ab2(0x94));_0x167b2e[_0x163ab2(0xa8)]&&_0x167b2e['title']['length']>0xc8&&_0x50327c[_0x163ab2(0xdc)]('Conversation\x20title\x20is\x20very\x20long\x20(>200\x20characters)');_0x167b2e['status']&&!Object[_0x163ab2(0xd0)](CONVERSATION_STATUS)[_0x163ab2(0x7d)](_0x167b2e['status'])&&_0xbc616e['push'](_0x163ab2(0x89)+_0x167b2e[_0x163ab2(0xa6)]);_0x167b2e['messages']&&!Array['isArray'](_0x167b2e['messages'])&&_0xbc616e[_0x163ab2(0xdc)](_0x163ab2(0xba));_0x167b2e[_0x163ab2(0xd5)]&&_0x167b2e['messages']['forEach']((_0x55491a,_0x29f01b)=>{const _0x55b4ad=_0x163ab2,_0x204779=this['validateMessage'](_0x55491a);_0x204779[_0x55b4ad(0xbe)]['forEach'](_0x4276ae=>{const _0x1e4d35=_0x55b4ad;_0xbc616e[_0x1e4d35(0xdc)]('Message\x20'+_0x29f01b+':\x20'+_0x4276ae);}),_0x204779['warnings']['forEach'](_0x738231=>{_0x50327c['push']('Message\x20'+_0x29f01b+':\x20'+_0x738231);});});_0x167b2e[_0x163ab2(0xc6)]!==undefined&&typeof _0x167b2e[_0x163ab2(0xc6)]!==_0x163ab2(0xb6)&&_0xbc616e['push']('Message\x20count\x20must\x20be\x20a\x20number');_0x167b2e['tokenCount']!==undefined&&typeof _0x167b2e['tokenCount']!==_0x163ab2(0xb6)&&_0xbc616e['push']('Token\x20count\x20must\x20be\x20a\x20number');_0x167b2e['cost']!==undefined&&typeof _0x167b2e['cost']!==_0x163ab2(0xb6)&&_0xbc616e[_0x163ab2(0xdc)](_0x163ab2(0xcf));_0x167b2e[_0x163ab2(0xa4)]&&!Array[_0x163ab2(0xd8)](_0x167b2e['participants'])&&_0xbc616e[_0x163ab2(0xdc)](_0x163ab2(0xd6));const _0x29ab4c=[_0x163ab2(0xac),'updatedAt',_0x163ab2(0xa2)];return _0x29ab4c['forEach'](_0x1bed1a=>{const _0x325ba5=_0x163ab2;_0x167b2e[_0x1bed1a]&&!this[_0x325ba5(0x6a)](_0x167b2e[_0x1bed1a])&&_0xbc616e[_0x325ba5(0xdc)](_0x325ba5(0x6f)+_0x1bed1a+':\x20'+_0x167b2e[_0x1bed1a]);}),{'isValid':_0xbc616e[_0x163ab2(0x8c)]===0x0,'errors':_0xbc616e,'warnings':_0x50327c};}static['validateMessage'](_0x20ef5c){const _0x5a13d7=a0_0x548405,_0x2cc166=[],_0x3ba7b6=[];(!_0x20ef5c['id']||typeof _0x20ef5c['id']!=='string')&&_0x2cc166['push'](_0x5a13d7(0x90));(!_0x20ef5c[_0x5a13d7(0x80)]||typeof _0x20ef5c[_0x5a13d7(0x80)]!==_0x5a13d7(0xe8))&&_0x2cc166[_0x5a13d7(0xdc)](_0x5a13d7(0x6e));(!_0x20ef5c['role']||typeof _0x20ef5c[_0x5a13d7(0x7a)]!=='string')&&_0x2cc166[_0x5a13d7(0xdc)](_0x5a13d7(0x83));_0x20ef5c['role']&&!Object[_0x5a13d7(0xd0)](MESSAGE_ROLES)[_0x5a13d7(0x7d)](_0x20ef5c[_0x5a13d7(0x7a)])&&_0x2cc166[_0x5a13d7(0xdc)]('Invalid\x20message\x20role:\x20'+_0x20ef5c[_0x5a13d7(0x7a)]);(!_0x20ef5c['content']||typeof _0x20ef5c[_0x5a13d7(0x74)]!=='string')&&_0x2cc166['push'](_0x5a13d7(0xc3));_0x20ef5c['content']&&_0x20ef5c[_0x5a13d7(0x74)]['length']>0x186a0&&_0x3ba7b6[_0x5a13d7(0xdc)](_0x5a13d7(0xeb));_0x20ef5c['role']===MESSAGE_ROLES[_0x5a13d7(0x81)]&&!_0x20ef5c[_0x5a13d7(0x76)]&&_0x2cc166[_0x5a13d7(0xdc)](_0x5a13d7(0xca));_0x20ef5c['role']===MESSAGE_ROLES['USER']&&!_0x20ef5c[_0x5a13d7(0xaf)]&&_0x3ba7b6[_0x5a13d7(0xdc)]('User\x20messages\x20should\x20have\x20a\x20userId');_0x20ef5c['contextReferences']&&!Array[_0x5a13d7(0xd8)](_0x20ef5c[_0x5a13d7(0xdd)])&&_0x2cc166[_0x5a13d7(0xdc)](_0x5a13d7(0x87));_0x20ef5c[_0x5a13d7(0xd4)]&&!Array['isArray'](_0x20ef5c['toolExecutions'])&&_0x2cc166[_0x5a13d7(0xdc)](_0x5a13d7(0x96));if(_0x20ef5c['tokenUsage']){const _0x43a1fe=this[_0x5a13d7(0x8b)](_0x20ef5c['tokenUsage']);_0x2cc166['push'](..._0x43a1fe[_0x5a13d7(0xbe)]),_0x3ba7b6['push'](..._0x43a1fe[_0x5a13d7(0x6b)]);}return _0x20ef5c['createdAt']&&!this['isValidTimestamp'](_0x20ef5c[_0x5a13d7(0xac)])&&_0x2cc166[_0x5a13d7(0xdc)]('Invalid\x20createdAt\x20timestamp:\x20'+_0x20ef5c['createdAt']),_0x20ef5c[_0x5a13d7(0x8f)]&&!this[_0x5a13d7(0x6a)](_0x20ef5c[_0x5a13d7(0x8f)])&&_0x2cc166['push']('Invalid\x20editedAt\x20timestamp:\x20'+_0x20ef5c[_0x5a13d7(0x8f)]),{'errors':_0x2cc166,'warnings':_0x3ba7b6};}static['validateTokenUsage'](_0x89377){const _0x2eded7=a0_0x548405,_0x3a971d=[],_0x36569c=[];(typeof _0x89377[_0x2eded7(0xa5)]!=='number'||_0x89377['totalTokens']<0x0)&&_0x3a971d[_0x2eded7(0xdc)]('Total\x20tokens\x20must\x20be\x20a\x20non-negative\x20number');_0x89377[_0x2eded7(0xb5)]!==undefined&&(typeof _0x89377[_0x2eded7(0xb5)]!=='number'||_0x89377[_0x2eded7(0xb5)]<0x0)&&_0x3a971d['push']('Prompt\x20tokens\x20must\x20be\x20a\x20non-negative\x20number');_0x89377[_0x2eded7(0xde)]!==undefined&&(typeof _0x89377['completionTokens']!=='number'||_0x89377['completionTokens']<0x0)&&_0x3a971d[_0x2eded7(0xdc)](_0x2eded7(0x7b));_0x89377[_0x2eded7(0xe1)]!==undefined&&(typeof _0x89377[_0x2eded7(0xe1)]!=='number'||_0x89377[_0x2eded7(0xe1)]<0x0)&&_0x3a971d[_0x2eded7(0xdc)]('Cost\x20must\x20be\x20a\x20non-negative\x20number');if(_0x89377[_0x2eded7(0xb5)]&&_0x89377[_0x2eded7(0xde)]){const _0x437932=_0x89377[_0x2eded7(0xb5)]+_0x89377['completionTokens'];Math['abs'](_0x437932-_0x89377['totalTokens'])>0x1&&_0x36569c[_0x2eded7(0xdc)](_0x2eded7(0xcb));}return{'errors':_0x3a971d,'warnings':_0x36569c};}static[a0_0x548405(0x6a)](_0x4dd586){const _0x5ed2f4=a0_0x548405;if(typeof _0x4dd586!=='string')return![];const _0x2c1cce=new Date(_0x4dd586);return _0x2c1cce instanceof Date&&!isNaN(_0x2c1cce[_0x5ed2f4(0x77)]());}}function a0_0x1143(){const _0x5b79cb=['y29UDgv4DfjLzMvYzw5Jzxm','y29TCgXLDgLVBLrVA2vUCW','z2v0q29UDMvYC2f0Aw9UrhvYyxrPB24','ywXS','y29ZDa','mZm3odqZr2HXqMfU','BMfTzq','B25Jzq','DgHYB3vNAa','mJiZnJi4nffmz0z2tq','ywjVDxq','C3rYAw5N','Bw9ZDa','zxH0CMfJDevUDgL0AwvZ','twvZC2fNzsbJB250zw50igLZihzLCNKGBg9UzYaOpJeWmdaWmcbJAgfYywn0zxjZkq','AxnwywXPzfrPBwvZDgfTCa','D2fYBMLUz3m','kIPdCMvHDgvKoIOQia','z2vUzxjHDgvtDw1Tyxj5','q29UDMvYC2f0Aw9UieLeigLZihjLCxvPCMvKigfUzcbTDxn0igjLigeGC3rYAw5N','sw52ywXPzcb0Aw1LC3rHBxaGzM9Yia','DgHL','mtbtqMrjy0S','D2HLBG','AxntDg9Wv29Yza','y29UDgvUDa','CgXHAw4','ywDLBNrjza','z2v0vgLTzq','C29YDa','z2vUzxjHDgvnzxnZywDLswq','CM9Szq','q29TCgXLDgLVBIb0B2TLBNmGBxvZDcbIzsbHig5VBI1UzwDHDgL2zsbUDw1Izxi','zNjVBq','Aw5JBhvKzxm','y2HHCKf0','yw5K','y29UDMvYC2f0Aw9Uswq','qvntsvnuqu5u','C2fTzq','twvZC2fNzsbYB2XLigLZihjLCxvPCMvKigfUzcbTDxn0igjLigeGC3rYAw5N','y3jLyxrLrgvMyxvSDe1LDgfKyxrH','Bwv0ywrHDge','iYmG','q29UDgv4DcbYzwzLCMvUy2vZig11C3qGyMuGyw4GyxjYyxK','ywDHAw4','sw52ywXPzcbJB252zxjZyxrPB24GC3rHDhvZoIa','u1Ltvevn','DMfSAwrHDgvuB2TLBLvZywDL','BgvUz3rO','CMvWzwf0','D2L0Aa','zwrPDgvKqxq','twvZC2fNzsbjrcbPCYbYzxf1AxjLzcbHBMqGBxvZDcbIzsbHihn0CMLUzW','yMvSB3C','nNblsvbHwq','zMLSDgvY','q29UDMvYC2f0Aw9UihrPDgXLigLZihjLCxvPCMvKigfUzcbTDxn0igjLigeGC3rYAw5N','CMvKDwnL','vg9VBcbLEgvJDxrPB25Zig11C3qGyMuGyw4GyxjYyxK','lI4U','z2v0u3rHDgLZDgLJCW','qwDLBNqGsuqGAxmGCMvXDwLYzwqGyw5Kig11C3qGyMuGysbZDhjPBMC','DgHLBG','y3jLyxrLrgvMyxvSDenVBNrLEhq','B3rOzxi','Dg9Rzw5vC2fNzq','Dg90ywXnzxnZywDLCW','mJeXotqXnwDoCKrsza','DMfSAwrHDgu','ANnVBG','BgfZDe1LC3nHz2vbDa','mJiYnde1nLrjEgTxzq','CgfYDgLJAxbHBNrZ','Dg90ywXuB2TLBNm','C3rHDhvZ','z2vUzxjHBa','DgL0Bgu','q3jLyxrLzdOG','Bwf0y2G','BM93','y3jLyxrLzef0','kIPdB250zxH0ifjLzMvYzw5Jzxm6kIOk','C2XPy2u','DxnLCKLK','y3jLyxrLrgvMyxvSDfnLDhrPBMDZ','Dg9mB2nHBgvtDhjPBMC','zM9YrwfJAa','C29Tzq','zM9YBwf0qxnnyxjRzg93BG','ChjVBxb0vg9Rzw5Z','BNvTyMvY','Dg9mB3DLCKnHC2u','y29UDMvYC2f0Aw9UrhvYyxrPB24','kqOk','twvZC2fNzxmGBxvZDcbIzsbHBIbHCNjHEq','z2v0','zM9YBwf0rM9YrxHWB3j0','nM9RueDbBq','zxjYB3jZ','nZu0ndqYmxr6vMntzG','y3jLyxrL','C3bSAxq','zw50CMLLCW','twvZC2fNzsbJB250zw50igLZihjLCxvPCMvKigfUzcbTDxn0igjLigeGC3rYAw5N','nZKZmtDMvxLfEei','qunusvzf','BwvZC2fNzunVDw50','CgfYzw50twvZC2fNzuLK','Dg9mB2nHBgvuAw1Lu3rYAw5N','C3vIC3rYAw5N','qxnZAxn0yw50ig1LC3nHz2vZig11C3qGAgf2zsbHBIbHz2vUDeLK','vg90ywWGDg9Rzw5ZigrVzxmGBM90ig1HDgnOihn1BsbVzIbWCM9TChqGyw5KignVBxbSzxrPB24GDg9Rzw5Z','mJaWBMnxsMHd','ANvZDa','ywrK','q29ZDcbTDxn0igjLigeGBNvTyMvY','DMfSDwvZ','mti3mJGYmgLXr3b3EG','mtfqDg9IqKO','zxH0CMfJDfrVCgLJCW','Dg9VBev4zwn1DgLVBNm','BwvZC2fNzxm','ugfYDgLJAxbHBNrZig11C3qGyMuGyw4GyxjYyxK','ywz0zxi','AxnbCNjHEq','Dg9vChbLCKnHC2u','C3vJAa','CMfUzg9T','ChvZAa'];a0_0x1143=function(){return _0x5b79cb;};return a0_0x1143();}function a0_0x93ef(_0xc43eb9,_0x15e48a){_0xc43eb9=_0xc43eb9-0x6a;const _0x114359=a0_0x1143();let _0x93ef93=_0x114359[_0xc43eb9];if(a0_0x93ef['whAxeF']===undefined){var _0x26e884=function(_0x13d314){const _0x37295c='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let _0x167b2e='',_0xbc616e='';for(let _0x50327c=0x0,_0x29ab4c,_0x55491a,_0x29f01b=0x0;_0x55491a=_0x13d314['charAt'](_0x29f01b++);~_0x55491a&&(_0x29ab4c=_0x50327c%0x4?_0x29ab4c*0x40+_0x55491a:_0x55491a,_0x50327c++%0x4)?_0x167b2e+=String['fromCharCode'](0xff&_0x29ab4c>>(-0x2*_0x50327c&0x6)):0x0){_0x55491a=_0x37295c['indexOf'](_0x55491a);}for(let _0x204779=0x0,_0x4276ae=_0x167b2e['length'];_0x204779<_0x4276ae;_0x204779++){_0xbc616e+='%'+('00'+_0x167b2e['charCodeAt'](_0x204779)['toString'](0x10))['slice'](-0x2);}return decodeURIComponent(_0xbc616e);};a0_0x93ef['bxiZbo']=_0x26e884,a0_0x93ef['JMCkme']={},a0_0x93ef['whAxeF']=!![];}const _0x429ce5=_0x114359[0x0],_0x45e847=_0xc43eb9+_0x429ce5,_0xc2a86=a0_0x93ef['JMCkme'][_0x45e847];return!_0xc2a86?(_0x93ef93=a0_0x93ef['bxiZbo'](_0x93ef93),a0_0x93ef['JMCkme'][_0x45e847]=_0x93ef93):_0x93ef93=_0xc2a86,_0x93ef93;}export class ConversationFactory{static[a0_0x548405(0xc0)](_0x381aed,_0x44a850,_0x52902c={}){const _0x16f37e=a0_0x548405,_0x2ed2c9=new Date()['toISOString'](),_0x55817f=this['generateConversationId']();return{'id':_0x55817f,'title':_0x44a850||'New\x20Conversation','agentId':_0x381aed,'status':CONVERSATION_STATUS[_0x16f37e(0xc5)],'messages':[],'metadata':this[_0x16f37e(0x84)](_0x52902c[_0x16f37e(0x85)]),'settings':this[_0x16f37e(0xb0)](_0x52902c['settings']),'context':this[_0x16f37e(0x9b)](),'createdAt':_0x2ed2c9,'updatedAt':_0x2ed2c9,'lastMessageAt':_0x2ed2c9,'messageCount':0x0,'tokenCount':0x0,'cost':0x0,'participants':[_0x381aed,..._0x52902c[_0x16f37e(0xa4)]||[]],'summary':{}};}static['createMessage'](_0x5e7cad,_0x5d22a9,_0x4b4a15,_0x2c6113={}){const _0x1fd299=a0_0x548405,_0x5acdd2=new Date()['toISOString'](),_0x28b88e=this[_0x1fd299(0x79)]();return{'id':_0x28b88e,'conversationId':_0x5e7cad,'role':_0x5d22a9,'content':_0x4b4a15,'agentId':_0x2c6113['agentId']||null,'userId':_0x2c6113[_0x1fd299(0xaf)]||null,'metadata':_0x2c6113[_0x1fd299(0x85)]||{},'contextReferences':_0x2c6113['contextReferences']||[],'toolExecutions':_0x2c6113[_0x1fd299(0xd4)]||[],'tokenUsage':_0x2c6113['tokenUsage']||null,'createdAt':_0x5acdd2,'editedAt':null,'parentMessageId':_0x2c6113[_0x1fd299(0xc7)]||null,'isEdited':![],'flags':_0x2c6113['flags']||{}};}static[a0_0x548405(0x84)](_0x805bcf={}){const _0x11bb18=a0_0x548405;return{'tags':[],'category':_0x11bb18(0xa7),'description':'','isBookmarked':![],'priority':0x3,'language':'en','customFields':{},'relatedConversations':[],..._0x805bcf};}static['createDefaultSettings'](_0x2141fa={}){return{'persistHistory':!![],'maxMessages':0x3e8,'autoSummarize':!![],'summarizeThreshold':0x32,'enableContextReferences':!![],'maxContextReferences':0xa,'notificationSettings':{'newMessage':!![],'agentResponse':!![],'toolExecution':![]},'privacySettings':{'shareHistory':![],'allowAnalytics':!![]},..._0x2141fa};}static['createDefaultContext'](){return{'currentTopic':null,'mentionedEntities':[],'variables':{},'activeTools':[],'workingMemory':{},'preferences':{},'phase':'initial','goals':{}};}static['generateConversationId'](){const _0x14f880=a0_0x548405,_0xb32902=Date[_0x14f880(0xab)]()['toString'](0x24),_0x15d383=Math[_0x14f880(0xdb)]()['toString'](0x24)['substr'](0x2,0x9);return'conv_'+_0xb32902+'_'+_0x15d383;}static['generateMessageId'](){const _0x45b0fd=a0_0x548405,_0x1f3d2a=Date[_0x45b0fd(0xab)]()['toString'](0x24),_0x239b38=Math[_0x45b0fd(0xdb)]()['toString'](0x24)['substr'](0x2,0x9);return'msg_'+_0x1f3d2a+'_'+_0x239b38;}}export class ConversationUtils{static[a0_0x548405(0x98)](_0x15df22){const _0x5f4561=a0_0x548405,_0x12186e=_0x15df22['messages']||[],_0x1f5e23=_0x12186e['filter'](_0x5b0511=>_0x5b0511['role']===MESSAGE_ROLES['USER']),_0x4307c7=_0x12186e[_0x5f4561(0x93)](_0x16d8b9=>_0x16d8b9['role']===MESSAGE_ROLES[_0x5f4561(0x81)]),_0xa435d6=_0x12186e['filter'](_0x25a777=>_0x25a777['role']===MESSAGE_ROLES[_0x5f4561(0x8a)]),_0x40d6a1=_0x12186e['reduce']((_0xf3e0f9,_0x938dbf)=>_0xf3e0f9+(_0x938dbf[_0x5f4561(0x9d)]?.[_0x5f4561(0xa5)]||0x0),0x0),_0x3b6b89=_0x12186e['reduce']((_0x419d13,_0x1f1b34)=>_0x419d13+(_0x1f1b34[_0x5f4561(0x9d)]?.[_0x5f4561(0xe1)]||0x0),0x0),_0x129174=_0x12186e['reduce']((_0x18c7e9,_0x2bc88b)=>_0x18c7e9+(_0x2bc88b['toolExecutions']?.[_0x5f4561(0x8c)]||0x0),0x0),_0x5899a3=_0x12186e[_0x5f4561(0x95)]((_0x14d290,_0x491f3c)=>_0x14d290+(_0x491f3c['contextReferences']?.['length']||0x0),0x0);return{'totalMessages':_0x12186e[_0x5f4561(0x8c)],'userMessages':_0x1f5e23[_0x5f4561(0x8c)],'assistantMessages':_0x4307c7['length'],'systemMessages':_0xa435d6['length'],'totalTokens':_0x40d6a1,'totalCost':_0x3b6b89,'toolExecutions':_0x129174,'contextReferences':_0x5899a3,'averageMessageLength':_0x12186e[_0x5f4561(0x8c)]>0x0?_0x12186e['reduce']((_0x11b8bb,_0x22eccb)=>_0x11b8bb+_0x22eccb[_0x5f4561(0x74)][_0x5f4561(0x8c)],0x0)/_0x12186e['length']:0x0,'conversationDuration':this[_0x5f4561(0xdf)](_0x15df22)};}static[a0_0x548405(0xdf)](_0x308fba){const _0xdcf8a7=a0_0x548405;if(!_0x308fba['messages']||_0x308fba['messages']['length']===0x0)return 0x0;const _0x2667f7=_0x308fba['messages'][0x0],_0x55a8b0=_0x308fba['messages'][_0x308fba['messages'][_0xdcf8a7(0x8c)]-0x1],_0x37d7c0=new Date(_0x2667f7[_0xdcf8a7(0xac)]),_0x279085=new Date(_0x55a8b0[_0xdcf8a7(0xac)]);return _0x279085['getTime']()-_0x37d7c0[_0xdcf8a7(0x77)]();}static[a0_0x548405(0x6d)](_0x539e09){const _0x28a1b7=a0_0x548405,_0x3adcc3=this[_0x28a1b7(0x98)](_0x539e09),_0x56f126=_0x539e09[_0x28a1b7(0xd5)]||[],_0x34cbea=this['extractTopics'](_0x56f126),_0x2ad869=this[_0x28a1b7(0xea)](_0x56f126),_0x46cb82=_0x56f126['slice'](-0xa),_0x3a92c4=_0x539e09[_0x28a1b7(0xa2)]||_0x539e09['updatedAt'];return{'title':_0x539e09[_0x28a1b7(0xa8)],'messageCount':_0x3adcc3[_0x28a1b7(0x9e)],'duration':_0x3adcc3[_0x28a1b7(0xb8)],'participants':_0x539e09['participants']['length'],'topics':_0x34cbea['slice'](0x0,0x5),'entities':_0x2ad869[_0x28a1b7(0xae)](0x0,0xa),'lastActivity':_0x3a92c4,'recentActivity':_0x46cb82['map'](_0x1bc8a0=>({'role':_0x1bc8a0[_0x28a1b7(0x7a)],'timestamp':_0x1bc8a0['createdAt'],'preview':_0x1bc8a0[_0x28a1b7(0x74)][_0x28a1b7(0xc9)](0x0,0x64)+(_0x1bc8a0[_0x28a1b7(0x74)][_0x28a1b7(0x8c)]>0x64?_0x28a1b7(0x97):'')})),'stats':_0x3adcc3};}static[a0_0x548405(0xd3)](_0x2e48b6){const _0x547f4a=a0_0x548405,_0x12b142=new Map();return _0x2e48b6[_0x547f4a(0xb2)](_0x4c1373=>{const _0x502bf7=_0x547f4a,_0x3c49d8=_0x4c1373[_0x502bf7(0x74)][_0x502bf7(0xb7)]()[_0x502bf7(0xc1)](/\s+/)[_0x502bf7(0x93)](_0x4b60ed=>_0x4b60ed['length']>0x3&&!this[_0x502bf7(0x73)](_0x4b60ed));_0x3c49d8['forEach'](_0x4cda4e=>{const _0x20b583=_0x502bf7;_0x12b142['set'](_0x4cda4e,(_0x12b142[_0x20b583(0xbb)](_0x4cda4e)||0x0)+0x1);});}),Array[_0x547f4a(0x7c)](_0x12b142[_0x547f4a(0xc2)]())[_0x547f4a(0x78)]((_0x52cc93,_0x3e0250)=>_0x3e0250[0x1]-_0x52cc93[0x1])['map'](([_0x41fbea])=>_0x41fbea);}static['extractEntities'](_0x3c7dc7){const _0x22844f=a0_0x548405,_0x27f782=new Set();return _0x3c7dc7['forEach'](_0x19141a=>{const _0x2703d3=a0_0x93ef,_0x22df9c=_0x19141a[_0x2703d3(0x74)][_0x2703d3(0xaa)](/\b[A-Z][a-z]+\b/g)||[];_0x22df9c['forEach'](_0x1eb666=>_0x27f782[_0x2703d3(0xce)](_0x1eb666));const _0x2c1b51=_0x19141a['content']['match'](/\b[\w\/\-\.]+\.\w+\b/g)||[];_0x2c1b51[_0x2703d3(0xb2)](_0x36ee79=>_0x27f782['add'](_0x36ee79));}),Array[_0x22844f(0x7c)](_0x27f782);}static[a0_0x548405(0x73)](_0x3e4e25){const _0x4ae6e9=a0_0x548405,_0x431849=new Set([_0x4ae6e9(0x70),_0x4ae6e9(0x7f),'or','but','in','on','at','to','for','of',_0x4ae6e9(0x8e),'by','from','up',_0x4ae6e9(0xe7),'into',_0x4ae6e9(0xe5),'during','before',_0x4ae6e9(0xd7),'above',_0x4ae6e9(0x91),'over','under',_0x4ae6e9(0x88),'further',_0x4ae6e9(0x9a),_0x4ae6e9(0xe4),'here','there',_0x4ae6e9(0x72),'where','why','how',_0x4ae6e9(0xe0),'any','both','each','few','more',_0x4ae6e9(0xe9),_0x4ae6e9(0x9c),_0x4ae6e9(0xb3),_0x4ae6e9(0xda),'only','own',_0x4ae6e9(0x82),'so','than','too','very','can','will',_0x4ae6e9(0xcd),'should',_0x4ae6e9(0xab)]);return _0x431849['has'](_0x3e4e25['toLowerCase']());}static[a0_0x548405(0xbc)](_0x1bef83,_0x330b4b=a0_0x548405(0xa1)){const _0x588211=a0_0x548405;switch(_0x330b4b){case'markdown':return this['formatAsMarkdown'](_0x1bef83);case _0x588211(0x75):return this['formatAsPlainText'](_0x1bef83);case'json':default:return JSON['stringify'](_0x1bef83,null,0x2);}}static[a0_0x548405(0xb4)](_0x49f327){const _0x1ca8b3=a0_0x548405;let _0x3c2767='#\x20'+_0x49f327[_0x1ca8b3(0xa8)]+'\x0a\x0a';return _0x3c2767+=_0x1ca8b3(0x6c)+new Date(_0x49f327[_0x1ca8b3(0xac)])[_0x1ca8b3(0xb1)]()+'\x0a',_0x3c2767+='**Agent:**\x20'+_0x49f327['agentId']+'\x0a',_0x3c2767+='**Messages:**\x20'+_0x49f327['messageCount']+'\x0a\x0a',_0x49f327['messages'][_0x1ca8b3(0xb2)](_0x3d29ee=>{const _0x59ad07=_0x1ca8b3,_0x3d1772=new Date(_0x3d29ee['createdAt'])[_0x59ad07(0xc8)](),_0x3cee37=_0x3d29ee['role'][_0x59ad07(0x7e)](0x0)['toUpperCase']()+_0x3d29ee[_0x59ad07(0x7a)]['slice'](0x1);_0x3c2767+=_0x59ad07(0x86)+_0x3cee37+'\x20('+_0x3d1772+_0x59ad07(0xb9),_0x3c2767+=_0x3d29ee['content']+'\x0a\x0a',_0x3d29ee[_0x59ad07(0xdd)]&&_0x3d29ee['contextReferences']['length']>0x0&&(_0x3c2767+=_0x59ad07(0xad),_0x3d29ee[_0x59ad07(0xdd)][_0x59ad07(0xb2)](_0x18500b=>{const _0x3b1a83=_0x59ad07;_0x3c2767+='-\x20'+_0x18500b[_0x3b1a83(0xe3)]+'\x20('+_0x18500b['type']+')\x0a';}),_0x3c2767+='\x0a');}),_0x3c2767;}static['formatAsPlainText'](_0x1f9f84){const _0x3926cb=a0_0x548405;let _0xeedf3f='Conversation:\x20'+_0x1f9f84['title']+'\x0a';return _0xeedf3f+=_0x3926cb(0xa9)+new Date(_0x1f9f84['createdAt'])['toLocaleString']()+'\x0a',_0xeedf3f+='Agent:\x20'+_0x1f9f84[_0x3926cb(0x76)]+'\x0a',_0xeedf3f+='Messages:\x20'+_0x1f9f84['messageCount']+'\x0a\x0a',_0xeedf3f+='-'[_0x3926cb(0x8d)](0x32)+'\x0a\x0a',_0x1f9f84[_0x3926cb(0xd5)][_0x3926cb(0xb2)](_0x4cd9c8=>{const _0xbc822b=_0x3926cb,_0x167af8=new Date(_0x4cd9c8[_0xbc822b(0xac)])['toLocaleTimeString'](),_0x465b9c=_0x4cd9c8[_0xbc822b(0x7a)][_0xbc822b(0xd9)]();_0xeedf3f+='['+_0x167af8+']\x20'+_0x465b9c+':\x0a',_0xeedf3f+=_0x4cd9c8[_0xbc822b(0x74)]+'\x0a\x0a';}),_0xeedf3f;}}export default{'ConversationValidator':ConversationValidator,'ConversationFactory':ConversationFactory,'ConversationUtils':ConversationUtils};