@sinequa/assistant 3.9.1 → 3.9.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 (48) hide show
  1. package/chat/chat.component.d.ts +35 -38
  2. package/chat/chat.service.d.ts +192 -84
  3. package/chat/debug-message/debug-message-details/debug-message-details.component.d.ts +19 -0
  4. package/chat/debug-message/debug-message.component.d.ts +9 -12
  5. package/chat/debug-message/debug-message.service.d.ts +15 -0
  6. package/chat/documents-upload/document-list/document-list.component.d.ts +1 -0
  7. package/chat/public-api.d.ts +0 -2
  8. package/chat/saved-chats/i18n/en.json +2 -1
  9. package/chat/saved-chats/i18n/fr.json +2 -1
  10. package/chat/saved-chats/saved-chats.component.d.ts +1 -0
  11. package/chat/saved-chats/saved-chats.service.d.ts +27 -0
  12. package/chat/services/assistant-configuration.service.d.ts +34 -0
  13. package/chat/services/assistant-metadata.service.d.ts +18 -0
  14. package/chat/services/assistant-tokens-tracking.service.d.ts +23 -0
  15. package/chat/services/assistant-ws-frames.service.d.ts +50 -0
  16. package/chat/services/signalR-connection.service.d.ts +25 -0
  17. package/chat/services/signalR.web.service.d.ts +1 -0
  18. package/chat/types.d.ts +24 -3
  19. package/chat/utils/utils.service.d.ts +67 -0
  20. package/esm2022/chat/chat-message/chat-message.component.mjs +3 -3
  21. package/esm2022/chat/chat.component.mjs +199 -225
  22. package/esm2022/chat/chat.service.mjs +452 -267
  23. package/esm2022/chat/debug-message/debug-message-details/debug-message-details.component.mjs +43 -0
  24. package/esm2022/chat/debug-message/debug-message.component.mjs +27 -30
  25. package/esm2022/chat/debug-message/debug-message.service.mjs +52 -0
  26. package/esm2022/chat/dialogs/rename-saved-chat.component.mjs +6 -5
  27. package/esm2022/chat/documents-upload/document-list/document-list.component.mjs +4 -2
  28. package/esm2022/chat/documents-upload/document-upload/document-upload.component.mjs +3 -3
  29. package/esm2022/chat/pipes/message-content.pipe.mjs +5 -2
  30. package/esm2022/chat/public-api.mjs +1 -3
  31. package/esm2022/chat/saved-chats/saved-chats.component.mjs +11 -10
  32. package/esm2022/chat/saved-chats/saved-chats.service.mjs +165 -0
  33. package/esm2022/chat/services/assistant-configuration.service.mjs +171 -0
  34. package/esm2022/chat/services/assistant-metadata.service.mjs +67 -0
  35. package/esm2022/chat/services/assistant-tokens-tracking.service.mjs +57 -0
  36. package/esm2022/chat/services/assistant-ws-frames.service.mjs +392 -0
  37. package/esm2022/chat/services/signalR-connection.service.mjs +109 -0
  38. package/esm2022/chat/services/signalR.web.service.mjs +1 -1
  39. package/esm2022/chat/types.mjs +2 -1
  40. package/esm2022/chat/unified-plugins/embedded-image-reference.plugin.mjs +2 -3
  41. package/esm2022/chat/utils/utils.service.mjs +170 -0
  42. package/fesm2022/sinequa-assistant-chat.mjs +2037 -1647
  43. package/fesm2022/sinequa-assistant-chat.mjs.map +1 -1
  44. package/package.json +1 -1
  45. package/chat/rest-chat.service.d.ts +0 -31
  46. package/chat/websocket-chat.service.d.ts +0 -102
  47. package/esm2022/chat/rest-chat.service.mjs +0 -296
  48. package/esm2022/chat/websocket-chat.service.mjs +0 -654
@@ -4,22 +4,20 @@ import { BehaviorSubject } from "rxjs";
4
4
  import { AppGlobalConfig, Article, Query } from "@sinequa/atomic";
5
5
  import { ChatService } from "./chat.service";
6
6
  import { InstanceManagerService } from "./instance-manager.service";
7
- import { RestChatService } from "./rest-chat.service";
8
7
  import { NotificationsService } from "./services/notification.service";
9
8
  import { PrincipalService } from "./services/principal.service";
10
9
  import { SearchService } from "./services/search.service";
11
10
  import { ChatConfig, ChatContextAttachment, ChatMessage, DebugMessage, GllmModelDescription, InitChat, MessageHandler, RawMessage, SuggestedAction } from "./types";
12
- import { WebSocketChatService } from "./websocket-chat.service";
13
11
  import * as i0 from "@angular/core";
14
12
  export declare class ChatComponent implements OnInit, OnChanges, OnDestroy {
15
- websocketService: WebSocketChatService;
16
- restService: RestChatService;
13
+ chatService: ChatService;
17
14
  instanceManagerService: InstanceManagerService;
18
15
  searchService: SearchService;
19
16
  principalService: PrincipalService;
20
17
  cdr: ChangeDetectorRef;
21
18
  notificationsService: NotificationsService;
22
19
  private readonly transloco;
20
+ private readonly assistantUtils;
23
21
  /** Define the key based on it, the chat service instance will be stored */
24
22
  instanceId: string;
25
23
  /** Define the query to use to fetch answers */
@@ -31,8 +29,6 @@ export declare class ChatComponent implements OnInit, OnChanges, OnDestroy {
31
29
  * @returns true if the chat should be reloaded, false otherwise
32
30
  */
33
31
  queryChangeShouldTriggerReload: (prevQuery: Query, newQuery: Query) => boolean;
34
- /** Define the protocol to be used for this chat instance*/
35
- protocol: 'REST' | 'WEBSOCKET';
36
32
  /** Map of listeners overriding default registered ones*/
37
33
  messageHandlers: Map<string, MessageHandler<any>>;
38
34
  /** When the assistant answer a user question, automatically scroll down to the bottom of the discussion */
@@ -73,7 +69,6 @@ export declare class ChatComponent implements OnInit, OnChanges, OnDestroy {
73
69
  tokenConsumptionTpl?: TemplateRef<any>;
74
70
  debugMessagesTpl?: TemplateRef<any>;
75
71
  appConfig: AppGlobalConfig;
76
- chatService: ChatService;
77
72
  config: ChatConfig;
78
73
  messages$: BehaviorSubject<ChatMessage[] | undefined>;
79
74
  isAdminOrDeletedAdmin: boolean;
@@ -82,8 +77,8 @@ export declare class ChatComponent implements OnInit, OnChanges, OnDestroy {
82
77
  private _dataSubscription;
83
78
  /** Variables that depend on the type of model in use */
84
79
  modelDescription?: GllmModelDescription;
85
- messageToEdit?: number;
86
- remappedMessageToEdit?: number;
80
+ indexMessageToEdit?: number;
81
+ rankMessageToEdit?: number;
87
82
  changes$: BehaviorSubject<SimpleChanges | undefined>;
88
83
  currentMessageIndex: number | undefined;
89
84
  firstChangesHandled: boolean;
@@ -103,7 +98,6 @@ export declare class ChatComponent implements OnInit, OnChanges, OnDestroy {
103
98
  showReport: boolean;
104
99
  debugMessages: DebugMessage[] | undefined;
105
100
  showDebugMessages: boolean;
106
- lastFetchDuration?: number;
107
101
  private _previousQuery;
108
102
  private _reloadSubscription;
109
103
  ngOnInit(): void;
@@ -111,8 +105,7 @@ export declare class ChatComponent implements OnInit, OnChanges, OnDestroy {
111
105
  ngOnDestroy(): void;
112
106
  get isAdmin(): boolean;
113
107
  /**
114
- * Instantiate the chat service based on the provided @input protocol
115
- * This chat service instance will then be stored in the instanceManagerService with provided @input instanceId as a key
108
+ * This chat service instance is stored in the instanceManagerService with provided @input instanceId as a key
116
109
  */
117
110
  instantiateChatService(): void;
118
111
  /**
@@ -244,9 +237,9 @@ export declare class ChatComponent implements OnInit, OnChanges, OnDestroy {
244
237
  * If the last message is from the user, a request to the assistant is made to get an answer
245
238
  * If the last message is from the assistant, the conversation is loaded right away
246
239
  * @param messages The list of messages of the chat
247
- * @param savedChatId The id of the saved chat. If provided (ie. an existing discussion in the saved chat index), update the savedChatId in the chat service for the upcoming saved chat operations
240
+ * @param chatId The id of the discussion. If provided (ie. an existing discussion in the saved chat index), update the chatId in the chat service for the upcoming saved chat operations
248
241
  */
249
- openChat(messages: RawMessage[], savedChatId?: string): void;
242
+ openChat(messages: RawMessage[], chatId?: string): void;
250
243
  /**
251
244
  * Reset the chat by clearing the chat history and the UI accordingly
252
245
  * The user input will be cleared
@@ -274,29 +267,26 @@ export declare class ChatComponent implements OnInit, OnChanges, OnDestroy {
274
267
  * Once the edited message is submitted, all subsequent messages starting from @param index will be removed from the history and the UI will be updated accordingly.
275
268
  * The assistant will regenerate a new answer based on the updated chat history.
276
269
  * ⚠️ If the assistant is streaming or stopping the generation, the operation is not allowed.
270
+ * @param message The user's message to edit
277
271
  * @param index The index of the user's message to edit
272
+ * @returns void
278
273
  */
279
- editMessage(index: number): void;
274
+ editMessage(message: ChatMessage, index: number): void;
280
275
  /**
281
276
  * Copy a previous assistant message of the chat history to the clipboard.
282
- * @param index The index of the assistant's message to edit
277
+ * @param message The message to copy
278
+ * @param index The index of the message to copy
279
+ * @returns void
283
280
  */
284
- copyMessage(index: number): void;
281
+ copyMessage(message: ChatMessage, index: number): void;
285
282
  /**
286
283
  * Starting from the provided index, remove all subsequent messages from the chat history and the UI accordingly.
287
284
  * The assistant will regenerate a new answer based on the updated chat history.
288
285
  * ⚠️ If the assistant is streaming or stopping the generation, the operation is not allowed.
286
+ * @param message The assistant's message to regenerate
289
287
  * @param index The index of the assistant's message to regenerate
290
288
  */
291
- regenerateMessage(index: number): void;
292
- /**
293
- * Remaps the index in the chat history.
294
- * The chat history is a list of messages where some messages can be hidden (display set to false).
295
- * The index provided as input is the index of the message in the chat history displayed in the UI.
296
- * This function should be removed once the backend is updated to add the ids of the messages in the chat history
297
- * @param index - The index to be remapped.
298
- */
299
- private _remapIndexInChatHistory;
289
+ regenerateMessage(message: ChatMessage, index: number): void;
300
290
  /**
301
291
  * Handles the key up event for 'Backspace' and 'Enter' keys.
302
292
  * @param event - The keyboard event.
@@ -311,16 +301,16 @@ export declare class ChatComponent implements OnInit, OnChanges, OnDestroy {
311
301
  /**
312
302
  * Send a "like" event on clicking on the thumb-up icon of an assistant's message
313
303
  * @param message The assistant message to like
314
- * @param rank The rank of the message to like
304
+ * @param index The index of the message to like
315
305
  */
316
- onLike(message: ChatMessage, rank: number): void;
306
+ onLike(message: ChatMessage, index: number): void;
317
307
  /**
318
308
  * Send a "dislike" event on clicking on the thumb-down icon of an assistant's message.
319
309
  * It also opens the issue reporting dialog.
320
310
  * @param message The assistant message to dislike
321
311
  * @param index The rank of the message to dislike
322
312
  */
323
- onDislike(message: ChatMessage, rank: number): void;
313
+ onDislike(message: ChatMessage, index: number): void;
324
314
  private _updateChatHistory;
325
315
  /**
326
316
  * Report an issue related to the assistant's message.
@@ -333,20 +323,25 @@ export declare class ChatComponent implements OnInit, OnChanges, OnDestroy {
333
323
  /**
334
324
  * Handle the click on a reference's 'open preview'.
335
325
  * @param data
336
- * @param index rank of the message
326
+ * @param message the message containing the reference
327
+ * @param index index of the message containing the reference
328
+ * @returns void
337
329
  */
338
330
  openAttachmentPreview(data: {
339
331
  reference: ChatContextAttachment;
340
332
  partId?: number;
341
- }, rank: number): void;
333
+ }, message: ChatMessage, index: number): void;
342
334
  /**
343
335
  * Handle the click on a reference's 'open original document'.
344
336
  * @param data
337
+ * @param message the message containing the reference
338
+ * @param index index of the message containing the reference
339
+ * @returns void
345
340
  */
346
341
  openOriginalAttachment(data: {
347
342
  reference: ChatContextAttachment;
348
343
  partId?: number;
349
- }, rank: number): void;
344
+ }, message: ChatMessage, index: number): void;
350
345
  /**
351
346
  * Handle the click on a suggested action.
352
347
  * @param action Suggested action.
@@ -355,16 +350,18 @@ export declare class ChatComponent implements OnInit, OnChanges, OnDestroy {
355
350
  suggestActionClick(action: SuggestedAction, index: number): void;
356
351
  /**
357
352
  * It looks for the debug messages available in the current group of "assistant" messages.
358
- * By design, the debug messages are only available in the first visible message among the group "assistant" messages.
359
- * @param index The rank of the message
353
+ * By design, the debug messages are only available in the first visible message among the group of "assistant" messages.
354
+ * @param message The message containing the debug information
355
+ * @param index The index of the message
360
356
  * @returns The debug messages available in the current group of "assistant" messages
361
357
  */
362
- getDebugMessages(index: number): DebugMessage[];
358
+ getDebugMessages(message: ChatMessage, index: number): DebugMessage[];
363
359
  /**
364
360
  * Handle the click on the 'show log info' button of a message.
365
- * @param index The rank of the message
361
+ * @param message The message containing the debug information
362
+ * @param index The index of the message
366
363
  */
367
- showDebug(index: number): void;
364
+ showDebug(message: ChatMessage, index: number): void;
368
365
  /**
369
366
  * Verify whether the current message is an assistant message and that all following messages are assistant ones
370
367
  * Used to keep the "View progress" opened even though the assistant is sending additional messages after the current one
@@ -384,5 +381,5 @@ export declare class ChatComponent implements OnInit, OnChanges, OnDestroy {
384
381
  */
385
382
  isEmptyAssistantMessage(message: ChatMessage | undefined): boolean;
386
383
  static ɵfac: i0.ɵɵFactoryDeclaration<ChatComponent, never>;
387
- static ɵcmp: i0.ɵɵComponentDeclaration<ChatComponent, "sq-chat-v3", never, { "instanceId": { "alias": "instanceId"; "required": false; }; "query": { "alias": "query"; "required": false; }; "queryChangeShouldTriggerReload": { "alias": "queryChangeShouldTriggerReload"; "required": false; }; "protocol": { "alias": "protocol"; "required": false; }; "messageHandlers": { "alias": "messageHandlers"; "required": false; }; "automaticScrollToLastResponse": { "alias": "automaticScrollToLastResponse"; "required": false; }; "focusAfterResponse": { "alias": "focusAfterResponse"; "required": false; }; "chat": { "alias": "chat"; "required": false; }; "assistantMessageIcon": { "alias": "assistantMessageIcon"; "required": false; }; "userMessageIcon": { "alias": "userMessageIcon"; "required": false; }; "connectionErrorMessageIcon": { "alias": "connectionErrorMessageIcon"; "required": false; }; "searchWarningMessageIcon": { "alias": "searchWarningMessageIcon"; "required": false; }; "additionalWorkflowProperties": { "alias": "additionalWorkflowProperties"; "required": false; }; "appConfig": { "alias": "appConfig"; "required": false; }; }, { "connection": "connection"; "loading$": "loading"; "_config": "config"; "data": "data"; "openDocument": "openDocument"; "openPreview": "openPreview"; "suggestAction": "suggestAction"; }, ["loadingTpl", "reportTpl", "tokenConsumptionTpl", "debugMessagesTpl"], never, true, never>;
384
+ static ɵcmp: i0.ɵɵComponentDeclaration<ChatComponent, "sq-chat-v3", never, { "instanceId": { "alias": "instanceId"; "required": false; }; "query": { "alias": "query"; "required": false; }; "queryChangeShouldTriggerReload": { "alias": "queryChangeShouldTriggerReload"; "required": false; }; "messageHandlers": { "alias": "messageHandlers"; "required": false; }; "automaticScrollToLastResponse": { "alias": "automaticScrollToLastResponse"; "required": false; }; "focusAfterResponse": { "alias": "focusAfterResponse"; "required": false; }; "chat": { "alias": "chat"; "required": false; }; "assistantMessageIcon": { "alias": "assistantMessageIcon"; "required": false; }; "userMessageIcon": { "alias": "userMessageIcon"; "required": false; }; "connectionErrorMessageIcon": { "alias": "connectionErrorMessageIcon"; "required": false; }; "searchWarningMessageIcon": { "alias": "searchWarningMessageIcon"; "required": false; }; "additionalWorkflowProperties": { "alias": "additionalWorkflowProperties"; "required": false; }; "appConfig": { "alias": "appConfig"; "required": false; }; }, { "connection": "connection"; "loading$": "loading"; "_config": "config"; "data": "data"; "openDocument": "openDocument"; "openPreview": "openPreview"; "suggestAction": "suggestAction"; }, ["loadingTpl", "reportTpl", "tokenConsumptionTpl", "debugMessagesTpl"], never, true, never>;
388
385
  }
@@ -1,17 +1,22 @@
1
1
  import { TranslocoService } from "@jsverse/transloco";
2
2
  import { BehaviorSubject, Observable } from "rxjs";
3
+ import { HubConnection } from "@microsoft/signalr";
3
4
  import { Query } from "@sinequa/atomic";
4
5
  import { AppService } from "./services/app.service";
5
- import { DialogService } from "./services/dialog.service";
6
6
  import { NotificationsService } from "./services/notification.service";
7
7
  import { PrincipalService } from "./services/principal.service";
8
8
  import { UserSettingsWebService } from "./services/user-settings.service";
9
- import { ChatConfig, ChatMessage, ChatResponse, ChatUsageMetrics, DeleteSavedChatResponse, GllmFunction, GllmModelDescription, Quota, SavedChat, SavedChatHistory, SavedChatResponse, TokenConsumption, UserTokenConsumption } from "./types";
9
+ import { ChatConfig, ChatMessage, ChatResponse, ChatUsageMetrics, DebugMessage, DeleteSavedChatResponse, GllmFunction, GllmModelDescription, KvObject, ListObject, MessageHandler, Quota, SavedChat, SavedChatHistory, SavedChatResponse, TokenConsumption, UserTokenConsumption } from "./types";
10
+ import { ConnectionOptions } from "./services/signalR.web.service";
11
+ import { AssistantUtils } from "./utils/utils.service";
10
12
  import * as i0 from "@angular/core";
11
- export declare abstract class ChatService {
12
- readonly localID: string | null;
13
- /** Name of the assistant plugin OR websocket endpoint. */
14
- REQUEST_URL: string;
13
+ export declare class ChatService {
14
+ /** Name of the assistant websocket endpoint. */
15
+ WS_REQUEST_URL: string;
16
+ /** Name of the assistant REST endpoint. */
17
+ REST_REQUEST_URL: string;
18
+ /** SignalR connection instance */
19
+ connection: HubConnection | undefined;
15
20
  /** Emit true once the initialization of the assistant process is done. */
16
21
  initProcess$: BehaviorSubject<boolean>;
17
22
  /** Emit true once the initialization of the assistant config is done. */
@@ -34,6 +39,8 @@ export declare abstract class ChatService {
34
39
  functions: GllmFunction[] | undefined;
35
40
  /** List of saved chats. */
36
41
  savedChats$: BehaviorSubject<SavedChat[]>;
42
+ /** Whether there is an error with saved chats. */
43
+ savedChatsError$: BehaviorSubject<boolean>;
37
44
  /** Emit the saved chat to load. */
38
45
  loadSavedChat$: BehaviorSubject<SavedChat | undefined>;
39
46
  /** Emit the quota each time the chat is invoked. */
@@ -48,26 +55,136 @@ export declare abstract class ChatService {
48
55
  stoppingGeneration$: BehaviorSubject<boolean>;
49
56
  /** Instance ID of the chat service defining the assistant instance. */
50
57
  private _chatInstanceId;
51
- /** ID of the current **saved chat** discussion which is used to update/get/delete it. */
52
- private _savedChatId;
53
- /** Generated GUID for the current non-saved chat discussion used to identify audit events.
54
- * If the chat is saved, the savedChatId is initialized with the value of this chatId.
55
- */
58
+ /** Generated GUID for the current chat discussion used to save/get/delete it and identify audit events. */
56
59
  private _chatId;
57
60
  userSettingsService: UserSettingsWebService;
58
61
  notificationsService: NotificationsService;
59
62
  appService: AppService;
60
- modalService: DialogService;
61
63
  principalService: PrincipalService;
64
+ assistantUtils: AssistantUtils;
65
+ private savedChatsService;
66
+ private signalRConnectionService;
67
+ private assistantConfigurationService;
68
+ private assistantMetadataService;
69
+ private assistantTokensTrackingService;
70
+ private debugMessageService;
71
+ private assistantWsFramesService;
62
72
  protected readonly transloco: TranslocoService;
63
73
  /**
64
- * Initialize the chat process
74
+ * Initialize the assistant process.
75
+ * It includes building and starting a connection, executing parallel requests for models and functions, and handling errors during the process.
76
+ * ⚠️ This method MUST be called ONLY if the user is loggedIn and once when the assistant is initialized.
77
+ *
78
+ * @returns An Observable<boolean> indicating the success of the initialization process.
79
+ */
80
+ init(): Observable<boolean>;
81
+ /**
82
+ * Define the endpoint to use for the websocket requests
83
+ * It can be overridden by the app config
65
84
  */
66
- abstract init(): Observable<boolean>;
85
+ getWSRequestsUrl(): void;
67
86
  /**
68
- * Initialize the REQUEST_URL
87
+ * Define the endpoint to use for the http requests
88
+ * It can be overridden by the app config
89
+ */
90
+ getRESTRequestsUrl(): void;
91
+ /**
92
+ * Initializes the SavedChatsService with the necessary configuration.
93
+ *
94
+ * This method sets up the `SavedChatsService` by providing it with a configuration object
95
+ * (`SavedChatsOperationConfig`) that includes various callbacks and properties required
96
+ * for its operation. The initialization will only proceed if both `assistantConfig$` and
97
+ * `REST_REQUEST_URL` are available.
98
+ *
99
+ * The configuration object includes:
100
+ * - Application name retrieval.
101
+ * - Instance ID retrieval.
102
+ * - REST API URL retrieval.
103
+ * - Debug flag retrieval.
104
+ * - Chat ID for new saves.
105
+ * - Saved chats enablement check.
106
+ * - Methods for setting a saved chat ID, updating the saved chats list, and generating audit events.
107
+ *
108
+ * If the required dependencies are not ready, an error is logged to the console.
109
+ *
110
+ * @private
111
+ */
112
+ private _initSavedChatsService;
113
+ /**
114
+ * Initializes the SignalR connection service with the necessary configuration.
115
+ *
116
+ * This method ensures that the SignalR connection service is properly set up
117
+ * by providing it with the required configuration values, such as the WebSocket
118
+ * request URL and assistant configuration. It also manages the SignalR hub connection
119
+ * instance.
120
+ *
121
+ * Preconditions:
122
+ * - `assistantConfig$.value` must be available.
123
+ * - `WS_REQUEST_URL` must be defined.
124
+ *
125
+ * If these preconditions are not met, an error is logged to the console.
126
+ *
127
+ * @private
128
+ */
129
+ private _initSignalRConnectionService;
130
+ /**
131
+ * Initializes the Assistant Configuration Service with the necessary operation context.
132
+ * This method sets up the configuration context by providing various utility functions
133
+ * and state management mechanisms required for the assistant's configuration operations.
134
+ *
135
+ * The operation context includes:
136
+ * - Methods to retrieve chat instance and chat IDs.
137
+ * - Methods to get and set assistant configuration values.
138
+ * - Methods to set WebSocket and REST request URLs.
139
+ * - Methods to update the initialization configuration status.
140
+ * - A method to generate audit events for tracking operations.
141
+ *
142
+ * @private
143
+ */
144
+ private _initAssistantConfigurationService;
145
+ /**
146
+ * Initializes the AssistantMetadataService with the necessary operation context.
147
+ *
148
+ * This method checks if the `assistantConfig$` value and `REST_REQUEST_URL` are available.
149
+ * If both are ready, it creates an `AssistantMetadataOperationContext` object and
150
+ * initializes the `assistantMetadataService` with it. The operation context provides
151
+ * methods to retrieve the REST URL, assistant configuration, and to set models and functions.
152
+ *
153
+ * If the required values are not ready, an error is logged to the console.
154
+ *
155
+ * @private
156
+ */
157
+ private _initAssistantMetadataService;
158
+ /**
159
+ * Initializes the Assistant Tokens Tracking Service with the necessary operation context.
160
+ * This method sets up the service by providing it with functions to manage quotas,
161
+ * token consumption, usage metrics, and audit events, as well as access to assistant configuration
162
+ * and model retrieval.
163
+ *
164
+ * The initialization will only proceed if the assistant configuration is available.
165
+ * If the configuration is not ready, an error message is logged to the console.
166
+ *
167
+ * @private
69
168
  */
70
- abstract getRequestsUrl(): void;
169
+ private _initAssistantTokensTrackingService;
170
+ /**
171
+ * Initializes the Assistant WebSocket Frames Service with the necessary operation context.
172
+ * This method sets up the required dependencies and configuration for the service to function properly.
173
+ * It ensures that the assistant configuration and connection are available before initializing the service.
174
+ *
175
+ * The operation context provides various utility functions and state management methods, including:
176
+ * - Accessing the assistant configuration, chat instance ID, saved chat ID, and chat history.
177
+ * - Managing streaming and stopping generation statuses.
178
+ * - Updating quota and chat usage metrics.
179
+ * - Generating audit events.
180
+ * - Managing saved chats (adding, updating, and listing).
181
+ *
182
+ * If the required dependencies (`assistantConfig$` and `connection`) are not ready, an error is logged.
183
+ *
184
+ * @private
185
+ */
186
+ private _initAssistantWsFramesService;
187
+ private _initDebugMessageService;
71
188
  get assistants(): any;
72
189
  /**
73
190
  * Get the instance ID of the chat service
@@ -80,23 +197,12 @@ export declare abstract class ChatService {
80
197
  */
81
198
  setChatInstanceId(instanceId: string): void;
82
199
  /**
83
- * Get the ID of the current chat discussion which is used to save/get/delete it
84
- * @returns The ID of the current chat discussion
85
- */
86
- get savedChatId(): string | undefined;
87
- /**
88
- * Persist the ID of the current chat discussion which is used to save/get/delete it
89
- * @param savedChatId The ID of the current chat discussion which is used to save/get/delete it
90
- */
91
- setSavedChatId(savedChatId: string | undefined): void;
92
- /**
93
- * Get the ID of the current chat discussion which is used to identify audit events
200
+ * Get the ID of the current chat discussion which is used to save/get/delete the discussion and identify audit events
94
201
  * @returns The ID of the current chat discussion
95
202
  */
96
203
  get chatId(): string;
97
204
  /**
98
- * Generate an GUID for the current chat discussion which is used to identify audit events
99
- * If the discussion is saved, the savedChatId is initialized with the value of this chatId
205
+ * Generate an GUID for the current chat discussion which is used to save/get/delete it and identify audit events
100
206
  * @param chatId if provided, it will be considered as the ID of the current chat discussion which is used to identify audit events
101
207
  */
102
208
  generateChatId(chatId?: string): void;
@@ -123,23 +229,23 @@ export declare abstract class ChatService {
123
229
  /**
124
230
  * Overrides the logged in user
125
231
  */
126
- abstract overrideUser(): void;
232
+ overrideUser(): void;
127
233
  /**
128
234
  * Calls the Fetch API to retrieve a new message given all previous messages
129
235
  */
130
- abstract fetch(messages: ChatMessage[], query: Query): Observable<ChatResponse>;
236
+ fetch(messages: ChatMessage[], query: Query): Observable<ChatResponse>;
131
237
  /**
132
238
  * Return the list of models available on the server
133
239
  */
134
- abstract listModels(): Observable<GllmModelDescription[] | undefined>;
240
+ listModels(): Observable<GllmModelDescription[] | undefined>;
135
241
  /**
136
242
  * Return the list of functions available on the server AND matching enabled functions in the chat config
137
243
  */
138
- abstract listFunctions(): Observable<GllmFunction[] | undefined>;
244
+ listFunctions(): Observable<GllmFunction[] | undefined>;
139
245
  /**
140
246
  * Stops the assistant answer generation and cancels all the ongoing and pending related tasks
141
247
  */
142
- abstract stopGeneration(): Observable<any>;
248
+ stopGeneration(): Observable<boolean>;
143
249
  /**
144
250
  * A handler for quota updates each time the chat is invoked.
145
251
  * It emits the updated quota to the quota$ subject, emits accordingly the updated user's tokens consumption and notifies the user if the max quota is reached.
@@ -164,18 +270,24 @@ export declare abstract class ChatService {
164
270
  /**
165
271
  * Fetch the list saved chats belonging to a specific instance of the assistant
166
272
  */
167
- abstract listSavedChat(): void;
273
+ listSavedChat(): void;
168
274
  /**
169
275
  * Return the saved chat with the given id, if exists. Otherwise, return undefined
170
276
  * @param id The id of the saved chat
171
277
  */
172
- abstract getSavedChat(id: string): Observable<SavedChatHistory | undefined>;
278
+ getSavedChat(id: string): Observable<SavedChatHistory | undefined>;
279
+ /**
280
+ * Check if a saved chat with the given id already exists
281
+ * @param id The id of the saved chat
282
+ * @returns True if the saved chat exists, false otherwise
283
+ */
284
+ isExistingSavedChat(id: string): Observable<boolean>;
173
285
  /**
174
286
  * Save a chat with the given messages
175
287
  * @param messages The messages to add to the saved chat index
176
288
  * @returns The saved chat
177
289
  */
178
- abstract addSavedChat(messages: ChatMessage[]): Observable<SavedChatResponse>;
290
+ addSavedChat(id: string, messages: ChatMessage[]): Observable<SavedChatResponse>;
179
291
  /**
180
292
  * Update a saved chat with the given id.
181
293
  * @param id The id of the saved chat
@@ -183,13 +295,54 @@ export declare abstract class ChatService {
183
295
  * @param messages The messages to update the saved chat history, if provided
184
296
  * @returns True if the saved chat has been successfully updated
185
297
  */
186
- abstract updateSavedChat(id: string, name?: string, messages?: ChatMessage[]): Observable<SavedChatResponse>;
298
+ updateSavedChat(id: string, name?: string, messages?: ChatMessage[]): Observable<SavedChatResponse>;
187
299
  /**
188
300
  * Bulk delete of saved chats matching the given ids
189
301
  * @param ids List of ids of the saved chats to delete
190
302
  * @returns The number of deleted chats
191
303
  */
192
- abstract deleteSavedChat(ids: string[]): Observable<DeleteSavedChatResponse>;
304
+ deleteSavedChat(ids: string[]): Observable<DeleteSavedChatResponse>;
305
+ getDebugMessage(message: DebugMessage): Observable<KvObject | ListObject | undefined>;
306
+ /**
307
+ * Initialize out-of-the-box handlers
308
+ * It is a placeholder for non-streaming scenarios, where you invoke a specific hub method, and the server responds with frame message(s)
309
+ */
310
+ initMessageHandlers(): void;
311
+ /**
312
+ * Override and register the entire _messageHandlers map by merging the provided map with the default one
313
+ * @param _messageHandlers
314
+ */
315
+ overrideMessageHandlers<T>(_messageHandlers: Map<string, MessageHandler<T>>): void;
316
+ /**
317
+ * Add a listener for a specific event.
318
+ * If a listener for this same event already exists, it will be overridden.
319
+ * If the listener has "isGlobalHandler" set to true, it will be registered to the hub connection.
320
+ * @param eventName Name of the event to register a listener for
321
+ * @param eventHandler The handler to be called when the event is received
322
+ */
323
+ addMessageHandler<T>(eventName: string, eventHandler: MessageHandler<T>): void;
324
+ /**
325
+ * Remove a listener for a specific event from the _messageHandlers map and unsubscribe from receiving messages for this event from the SignalR hub.
326
+ * @param eventName Name of the event to remove the listener for
327
+ */
328
+ removeMessageHandler(eventName: string): void;
329
+ /**
330
+ * Build a connection to the signalR websocket and register default listeners to the methods defined in the server hub class
331
+ * @param options The options for the connection. It overrides the default options
332
+ * @param logLevel Define the log level displayed in the console
333
+ * @returns Promise that resolves when the connection is built
334
+ */
335
+ buildConnection(options?: ConnectionOptions): Promise<void>;
336
+ /**
337
+ * Start the connection
338
+ * @returns Promise that resolves when the connection is started
339
+ */
340
+ startConnection(): Promise<void>;
341
+ /**
342
+ * Stop the connection
343
+ * @returns Promise that resolves when the connection is stopped
344
+ */
345
+ stopConnection(): Promise<void>;
193
346
  /**
194
347
  * Generate an audit event with the given type and details. The generated audit event is sent afterwards via the AuditWebService
195
348
  * @param type Audit event type
@@ -197,51 +350,6 @@ export declare abstract class ChatService {
197
350
  * @param id Actions (savedChat delete/rename/...) may occur on a specific chat different than the current one stored in this service, so the chat id can be provided
198
351
  */
199
352
  generateAuditEvent(type: string, details: Record<string, any>, id?: string): Promise<void>;
200
- /**
201
- * Traverse the array from the end and track the first 'assistant' message among the last group of "assistant" messages where display is true
202
- * @param array The array of ChatMessage to traverse
203
- * @returns The index of the first visible assistant message among the last group of "assistant" messages in the array
204
- */
205
- firstVisibleAssistantMessageIndex(array: ChatMessage[] | undefined): number;
206
- /**
207
- * Traverse the array from the end and pick the last 'assistant' message among the last group of "assistant" messages where display is true
208
- * @param array The array of ChatMessage to traverse
209
- * @returns The index of the last visible assistant message among the last group of "assistant" messages in the array
210
- */
211
- lastVisibleAssistantMessageIndex(array: ChatMessage[] | undefined): number;
212
- /**
213
- * Format a date string in UTC to a local date string
214
- * @param value Date string in UTC to format
215
- * @returns A formatted local date string
216
- */
217
- protected formatDateTime(value: string): string;
218
- /**
219
- * Takes a text prompt that may contain placeholders for variables
220
- * and replaces these placeholders if it finds a match in the given
221
- * context object.
222
- *
223
- * @example
224
- * const p = "Hello, [[user.name]]! You have [[user.notifications.length]] new notifications.";
225
- * const context = {
226
- * user: {
227
- * name: "Alice",
228
- * notifications: ["Message from Bob", "Reminder for meeting"]
229
- * }
230
- * };
231
- * const formattedPrompt = formatPrompt(p, context);
232
- * console.log(formattedPrompt); // Output: "Hello, Alice! You have 2 new notifications."
233
- */
234
- static formatPrompt(prompt: string, context: any): string;
235
- /**
236
- * Determines a time-based key for a given date to be used for translations or formatting.
237
- * The key represents a relative time period such as "today", "yesterday", "this week", etc.
238
- * If the date does not fall into any predefined relative time period, it returns the year as a string.
239
- *
240
- * @param date - The date for which the time key is to be determined.
241
- * @returns A string representing the time key, which can be used for translation or display purposes.
242
- */
243
- getTimeKey(date: Date): string;
244
- getCurrentLocaleName(): string;
245
353
  static ɵfac: i0.ɵɵFactoryDeclaration<ChatService, never>;
246
354
  static ɵprov: i0.ɵɵInjectableDeclaration<ChatService>;
247
355
  }
@@ -0,0 +1,19 @@
1
+ import { AfterViewInit } from "@angular/core";
2
+ import { KvObject, ListObject } from "../../types";
3
+ import { UIService } from "../../services/ui.service";
4
+ import { DebugMessageService } from "../debug-message.service";
5
+ import * as i0 from "@angular/core";
6
+ export declare class DebugMessageDetailsComponent implements AfterViewInit {
7
+ ui: UIService;
8
+ debugMessageService: DebugMessageService;
9
+ data: (KvObject | ListObject)[] | undefined;
10
+ level: number;
11
+ parentColor: string;
12
+ constructor(ui: UIService, debugMessageService: DebugMessageService);
13
+ ngAfterViewInit(): void;
14
+ isObject(value: any): boolean;
15
+ getRowClass(item: KvObject | ListObject): string;
16
+ copyToClipboard(code: any): void;
17
+ static ɵfac: i0.ɵɵFactoryDeclaration<DebugMessageDetailsComponent, never>;
18
+ static ɵcmp: i0.ɵɵComponentDeclaration<DebugMessageDetailsComponent, "sq-debug-message-details", never, { "data": { "alias": "data"; "required": false; }; "level": { "alias": "level"; "required": false; }; "parentColor": { "alias": "parentColor"; "required": false; }; }, {}, never, never, true, never>;
19
+ }
@@ -1,17 +1,14 @@
1
- import { AfterViewInit } from "@angular/core";
1
+ import { ChangeDetectorRef } from "@angular/core";
2
2
  import { DebugMessage } from "../types";
3
- import { UIService } from "../services/ui.service";
3
+ import { DebugMessageService } from "./debug-message.service";
4
4
  import * as i0 from "@angular/core";
5
- export declare class DebugMessageComponent implements AfterViewInit {
6
- ui: UIService;
5
+ export declare class DebugMessageComponent {
6
+ debugMessageService: DebugMessageService;
7
+ cdr: ChangeDetectorRef;
7
8
  data: DebugMessage[] | undefined;
8
- level: number;
9
- parentColor: string;
10
- constructor(ui: UIService);
11
- ngAfterViewInit(): void;
12
- isObject(value: any): boolean;
13
- getRowClass(item: DebugMessage, index: number): string;
14
- copyToClipboard(code: any): void;
9
+ constructor(debugMessageService: DebugMessageService, cdr: ChangeDetectorRef);
10
+ getRowClass(index: number): string;
11
+ toggleExpand(item: DebugMessage): void;
15
12
  static ɵfac: i0.ɵɵFactoryDeclaration<DebugMessageComponent, never>;
16
- static ɵcmp: i0.ɵɵComponentDeclaration<DebugMessageComponent, "sq-debug-message", never, { "data": { "alias": "data"; "required": false; }; "level": { "alias": "level"; "required": false; }; "parentColor": { "alias": "parentColor"; "required": false; }; }, {}, never, never, true, never>;
13
+ static ɵcmp: i0.ɵɵComponentDeclaration<DebugMessageComponent, "sq-debug-message", never, { "data": { "alias": "data"; "required": false; }; }, {}, never, never, true, never>;
17
14
  }
@@ -0,0 +1,15 @@
1
+ import { Observable } from 'rxjs';
2
+ import { DebugMessage, ListObject } from '../types';
3
+ import * as i0 from "@angular/core";
4
+ export interface DebugMessageOperationConfig {
5
+ getRestUrl: () => string;
6
+ }
7
+ export declare class DebugMessageService {
8
+ private operationConfig;
9
+ constructor();
10
+ init(config: DebugMessageOperationConfig): void;
11
+ private ensureInitialized;
12
+ getDebugMessage(message: DebugMessage): Observable<ListObject | undefined>;
13
+ static ɵfac: i0.ɵɵFactoryDeclaration<DebugMessageService, never>;
14
+ static ɵprov: i0.ɵɵInjectableDeclaration<DebugMessageService>;
15
+ }
@@ -21,6 +21,7 @@ export declare class DocumentListComponent implements OnInit, OnDestroy {
21
21
  documentsUploadService: DocumentsUploadService;
22
22
  notificationsService: NotificationsService;
23
23
  private readonly transloco;
24
+ private readonly assistantUtils;
24
25
  ngOnInit(): void;
25
26
  ngOnDestroy(): void;
26
27
  instantiateChatService(): void;