@sinequa/assistant 3.9.2 → 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 (43) hide show
  1. package/chat/chat.component.d.ts +35 -38
  2. package/chat/chat.service.d.ts +190 -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 +1 -1
  9. package/chat/saved-chats/i18n/fr.json +1 -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/types.d.ts +12 -3
  18. package/chat/utils/utils.service.d.ts +67 -0
  19. package/esm2022/chat/chat.component.mjs +198 -227
  20. package/esm2022/chat/chat.service.mjs +450 -267
  21. package/esm2022/chat/debug-message/debug-message-details/debug-message-details.component.mjs +43 -0
  22. package/esm2022/chat/debug-message/debug-message.component.mjs +27 -30
  23. package/esm2022/chat/debug-message/debug-message.service.mjs +52 -0
  24. package/esm2022/chat/dialogs/rename-saved-chat.component.mjs +6 -5
  25. package/esm2022/chat/documents-upload/document-list/document-list.component.mjs +4 -2
  26. package/esm2022/chat/public-api.mjs +1 -3
  27. package/esm2022/chat/saved-chats/saved-chats.component.mjs +11 -10
  28. package/esm2022/chat/saved-chats/saved-chats.service.mjs +165 -0
  29. package/esm2022/chat/services/assistant-configuration.service.mjs +171 -0
  30. package/esm2022/chat/services/assistant-metadata.service.mjs +67 -0
  31. package/esm2022/chat/services/assistant-tokens-tracking.service.mjs +57 -0
  32. package/esm2022/chat/services/assistant-ws-frames.service.mjs +392 -0
  33. package/esm2022/chat/services/signalR-connection.service.mjs +109 -0
  34. package/esm2022/chat/types.mjs +1 -1
  35. package/esm2022/chat/unified-plugins/embedded-image-reference.plugin.mjs +2 -3
  36. package/esm2022/chat/utils/utils.service.mjs +170 -0
  37. package/fesm2022/sinequa-assistant-chat.mjs +2020 -1648
  38. package/fesm2022/sinequa-assistant-chat.mjs.map +1 -1
  39. package/package.json +1 -1
  40. package/chat/rest-chat.service.d.ts +0 -31
  41. package/chat/websocket-chat.service.d.ts +0 -102
  42. package/esm2022/chat/rest-chat.service.mjs +0 -300
  43. package/esm2022/chat/websocket-chat.service.mjs +0 -659
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "rename": "Rename",
3
3
  "delete": "Delete",
4
- "error": "Oops! We're having trouble loading your past chats right now. Please try again later. If the problem persists, contact support for assistance."
4
+ "listError": "Oops! We're having trouble loading your past chats right now. Please try again later. If the problem persists, contact support for assistance."
5
5
  }
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "rename": "Renommer",
3
3
  "delete": "Supprimer",
4
- "error": "Oups ! Nous avons un problème pour charger vos anciennes conversations. Veuillez réessayer plus tard. Si le problème persiste, contactez le support pour assistance."
4
+ "listError": "Oups ! Nous avons un problème pour charger vos anciennes conversations. Veuillez réessayer plus tard. Si le problème persiste, contactez le support pour assistance."
5
5
  }
@@ -19,6 +19,7 @@ export declare class SavedChatsComponent implements OnInit, OnDestroy {
19
19
  instanceManagerService: InstanceManagerService;
20
20
  notificationsService: NotificationsService;
21
21
  private readonly transloco;
22
+ private readonly assistantUtils;
22
23
  ngOnInit(): void;
23
24
  ngOnDestroy(): void;
24
25
  instantiateChatService(): void;
@@ -0,0 +1,27 @@
1
+ import { Observable } from 'rxjs';
2
+ import { ChatMessage, SavedChat, SavedChatHistory, SavedChatResponse, DeleteSavedChatResponse } from '../types';
3
+ import * as i0 from "@angular/core";
4
+ export interface SavedChatsOperationConfig {
5
+ getAppName: () => string;
6
+ getInstanceId: () => string;
7
+ getRestUrl: () => string;
8
+ getDebugFlag: () => boolean;
9
+ isSavedChatsEnabled: () => boolean;
10
+ setSavedChatsErrorStatus: (hasError: boolean) => void;
11
+ updateSavedChatsList: (chats: SavedChat[]) => void;
12
+ generateAuditEvent: (type: string, details: Record<string, any>, id?: string) => Promise<void>;
13
+ }
14
+ export declare class SavedChatsService {
15
+ private operationConfig;
16
+ constructor();
17
+ init(config: SavedChatsOperationConfig): void;
18
+ private ensureInitialized;
19
+ listChats(): void;
20
+ getChatById(id: string): Observable<SavedChatHistory | undefined>;
21
+ addChat(id: string, messages: ChatMessage[]): Observable<SavedChatResponse>;
22
+ updateChat(id: string, name?: string, messages?: ChatMessage[]): Observable<SavedChatResponse>;
23
+ deleteChat(ids: string[]): Observable<DeleteSavedChatResponse>;
24
+ isExistingChat(id: string): Observable<boolean>;
25
+ static ɵfac: i0.ɵɵFactoryDeclaration<SavedChatsService, never>;
26
+ static ɵprov: i0.ɵɵInjectableDeclaration<SavedChatsService>;
27
+ }
@@ -0,0 +1,34 @@
1
+ import { ChatConfig } from '../types';
2
+ import * as i0 from "@angular/core";
3
+ export interface AssistantConfigurationOperationContext {
4
+ getChatInstanceId: () => string;
5
+ getChatId: () => string;
6
+ getAssistantConfigValue: () => ChatConfig | undefined;
7
+ setAssistantConfig: (config: ChatConfig | undefined) => void;
8
+ setWSRequestsUrl: (url: string) => void;
9
+ setRESTRequestsUrl: (url: string) => void;
10
+ setInitConfigStatus: (status: boolean) => void;
11
+ generateAuditEvent: (type: string, details: Record<string, any>, id?: string) => Promise<void>;
12
+ }
13
+ export declare class AssistantConfigurationService {
14
+ private context;
15
+ private appService;
16
+ private userSettingsService;
17
+ private principalService;
18
+ private modalService;
19
+ private notificationsService;
20
+ private transloco;
21
+ constructor();
22
+ init(context: AssistantConfigurationOperationContext): void;
23
+ private ensureInitialized;
24
+ getAssistantsSetting(): any;
25
+ initChatConfig(): Promise<void>;
26
+ updateChatConfig(config: ChatConfig, hashes?: {
27
+ "applied-defaultValues-hash"?: string;
28
+ "skipped-defaultValues-hash"?: string;
29
+ }, notify?: boolean, successCallback?: () => any, errorCallback?: () => any): void;
30
+ getWSRequestsUrl(): void;
31
+ getRESTRequestsUrl(): void;
32
+ static ɵfac: i0.ɵɵFactoryDeclaration<AssistantConfigurationService, never>;
33
+ static ɵprov: i0.ɵɵInjectableDeclaration<AssistantConfigurationService>;
34
+ }
@@ -0,0 +1,18 @@
1
+ import { Observable } from 'rxjs';
2
+ import { ChatConfig, GllmModelDescription, GllmFunction } from '../types';
3
+ import * as i0 from "@angular/core";
4
+ export interface AssistantMetadataOperationContext {
5
+ getRestUrl: () => string;
6
+ getAssistantConfigValue: () => ChatConfig | undefined;
7
+ setModels: (models: GllmModelDescription[] | undefined) => void;
8
+ setFunctions: (functions: GllmFunction[] | undefined) => void;
9
+ }
10
+ export declare class AssistantMetadataService {
11
+ private context;
12
+ init(context: AssistantMetadataOperationContext): void;
13
+ private ensureInitialized;
14
+ listModels(): Observable<GllmModelDescription[] | undefined>;
15
+ listFunctions(): Observable<GllmFunction[] | undefined>;
16
+ static ɵfac: i0.ɵɵFactoryDeclaration<AssistantMetadataService, never>;
17
+ static ɵprov: i0.ɵɵInjectableDeclaration<AssistantMetadataService>;
18
+ }
@@ -0,0 +1,23 @@
1
+ import { ChatConfig, ChatUsageMetrics, GllmModelDescription, Quota, TokenConsumption, UserTokenConsumption } from '../types';
2
+ import * as i0 from "@angular/core";
3
+ export interface AssistantTokensTrackingOperationContext {
4
+ getAssistantConfigValue: () => ChatConfig | undefined;
5
+ setQuota: (quota: Quota | undefined) => void;
6
+ setUserTokenConsumption: (consumption: UserTokenConsumption | undefined) => void;
7
+ setChatUsageMetrics: (metrics: ChatUsageMetrics | undefined) => void;
8
+ setChatTokenConsumption: (consumption: TokenConsumption | undefined) => void;
9
+ generateAuditEvent: (type: string, details: Record<string, any>, id?: string) => Promise<void>;
10
+ getModel: (serviceId: string, modelId: string) => GllmModelDescription | undefined;
11
+ }
12
+ export declare class AssistantTokensTrackingService {
13
+ private context;
14
+ private assistantUtils;
15
+ private notificationsService;
16
+ constructor();
17
+ init(context: AssistantTokensTrackingOperationContext): void;
18
+ private ensureInitialized;
19
+ updateQuota(quota: Quota, propagateError?: boolean): void;
20
+ updateChatUsageMetrics(chatUsageMetrics: ChatUsageMetrics): void;
21
+ static ɵfac: i0.ɵɵFactoryDeclaration<AssistantTokensTrackingService, never>;
22
+ static ɵprov: i0.ɵɵInjectableDeclaration<AssistantTokensTrackingService>;
23
+ }
@@ -0,0 +1,50 @@
1
+ import { HubConnection } from '@microsoft/signalr';
2
+ import { Observable } from 'rxjs';
3
+ import { Query } from "@sinequa/atomic";
4
+ import { ChatConfig, ChatMessage, ChatResponse, ChatUsageMetrics, MessageHandler, Quota, SavedChatResponse } from '../types';
5
+ import * as i0 from "@angular/core";
6
+ export interface AssistantWsFramesContext {
7
+ getAssistantConfig: () => ChatConfig | undefined;
8
+ getChatInstanceId: () => string;
9
+ getChatId: () => string;
10
+ getHubConnection: () => HubConnection | undefined;
11
+ getChatHistory: () => ChatMessage[] | undefined;
12
+ setStreamingStatus: (isStreaming: boolean) => void;
13
+ setChatHistory: (history: ChatMessage[] | undefined) => void;
14
+ setStoppingGenerationStatus: (isStopping: boolean) => void;
15
+ setSavedChatsErrorStatus: (hasError: boolean) => void;
16
+ updateQuota: (quota: Quota, propagateError?: boolean) => void;
17
+ updateChatUsageMetrics: (metrics: ChatUsageMetrics) => void;
18
+ generateAuditEvent: (type: string, details: Record<string, any>, id?: string) => Promise<void>;
19
+ addSavedChat: (id: string, messages: ChatMessage[]) => Observable<SavedChatResponse>;
20
+ updateSavedChat: (id: string, name?: string, messages?: ChatMessage[]) => Observable<SavedChatResponse>;
21
+ listSavedChat: () => void;
22
+ isExistingSavedChat: (id: string) => Observable<boolean>;
23
+ }
24
+ export declare class AssistantWsFramesService {
25
+ private context;
26
+ private appService;
27
+ private transloco;
28
+ private assistantUtils;
29
+ private notificationsService;
30
+ private _messageHandlers;
31
+ private _response;
32
+ private _actionMap;
33
+ private _progress;
34
+ private _executionTime;
35
+ private _executionTimeMilliseconds?;
36
+ private _attachments;
37
+ private _debugMessages;
38
+ init(context: AssistantWsFramesContext): void;
39
+ private ensureInitialized;
40
+ fetch(messages: ChatMessage[], query: Query): Observable<ChatResponse>;
41
+ initMessageHandlers(): void;
42
+ overrideMessageHandlers<T>(_messageHandlers: Map<string, MessageHandler<T>>): void;
43
+ addMessageHandler<T>(eventName: string, eventHandler: MessageHandler<T>): void;
44
+ registerMessageHandler<T>(eventName: string, eventHandler: MessageHandler<T>): void;
45
+ removeMessageHandler(eventName: string): void;
46
+ unsubscribeMessageHandler(eventName: string): void;
47
+ stopGeneration(): Observable<boolean>;
48
+ static ɵfac: i0.ɵɵFactoryDeclaration<AssistantWsFramesService, never>;
49
+ static ɵprov: i0.ɵɵInjectableDeclaration<AssistantWsFramesService>;
50
+ }
@@ -0,0 +1,25 @@
1
+ import { HubConnection } from '@microsoft/signalr';
2
+ import { ConnectionOptions } from './signalR.web.service';
3
+ import { ChatConfig } from '../types';
4
+ import * as i0 from "@angular/core";
5
+ export interface SignalRConnectionOperationConfig {
6
+ getWsRequestUrl: () => string;
7
+ getAssistantConfigValue: () => ChatConfig | undefined;
8
+ getHubConnection: () => HubConnection | undefined;
9
+ setHubConnection: (connection: HubConnection | undefined) => void;
10
+ }
11
+ export declare class SignalRConnectionService {
12
+ private operationConfig;
13
+ private signalRWebService;
14
+ private assistantUtils;
15
+ init(config: SignalRConnectionOperationConfig): void;
16
+ private ensureInitialized;
17
+ private _getLogLevel;
18
+ private _getTransports;
19
+ private getDefaultOptions;
20
+ buildConnection(options?: ConnectionOptions): Promise<void>;
21
+ startConnection(): Promise<void>;
22
+ stopConnection(): Promise<void>;
23
+ static ɵfac: i0.ɵɵFactoryDeclaration<SignalRConnectionService, never>;
24
+ static ɵprov: i0.ɵɵInjectableDeclaration<SignalRConnectionService>;
25
+ }
package/chat/types.d.ts CHANGED
@@ -24,6 +24,7 @@ export interface RawMessage {
24
24
  */
25
25
  export interface ChatMessage extends RawMessage {
26
26
  additionalProperties: {
27
+ messageId: string;
27
28
  display?: boolean;
28
29
  $progress?: ChatProgress[];
29
30
  $attachment?: ChatContextAttachment[];
@@ -792,8 +793,8 @@ export interface ChatPayload {
792
793
  targetUrl?: string;
793
794
  accessToken?: string;
794
795
  };
795
- instanceId?: string;
796
- savedChatId?: string;
796
+ instanceId: string;
797
+ chatId: string;
797
798
  genericChatErrorMessage?: string;
798
799
  }
799
800
  export type ActionMessage = {
@@ -904,7 +905,15 @@ export interface ListObject {
904
905
  items: (KvObject | ListObject)[];
905
906
  expanded: boolean;
906
907
  }
907
- export type DebugMessage = KvObject | ListObject;
908
+ export type DebugMessage = {
909
+ title: string;
910
+ chatId: string;
911
+ executionId: string;
912
+ debugMessageId: string;
913
+ $expanded?: boolean;
914
+ $loading?: boolean;
915
+ $details?: ListObject[];
916
+ };
908
917
  export type MessageHandler<T> = {
909
918
  handler: (data: T) => void;
910
919
  isGlobalHandler: boolean;
@@ -0,0 +1,67 @@
1
+ import { TranslocoService } from "@jsverse/transloco";
2
+ import { ChatMessage } from "../types";
3
+ import * as i0 from "@angular/core";
4
+ export declare class AssistantUtils {
5
+ readonly localID: string | null;
6
+ protected readonly transloco: TranslocoService;
7
+ /**
8
+ * Retrieves the rank (1-based index) of a message within a chat history array based on its message ID.
9
+ * If the message is not found, returns -1.
10
+ *
11
+ * @param array - An array of `ChatMessage` objects or `undefined`. Represents the chat history.
12
+ * @param messageId - The unique identifier of the message to locate.
13
+ * @returns The 1-based index of the message in the array, or -1 if the message is not found.
14
+ */
15
+ getMessageRankInChatHistory(array: ChatMessage[] | undefined, messageId: string): number;
16
+ /**
17
+ * Traverse the array from the end and track the first 'assistant' message among the last group of "assistant" messages where display is true
18
+ * @param array The array of ChatMessage to traverse
19
+ * @returns The index of the first visible assistant message among the last group of "assistant" messages in the array
20
+ */
21
+ firstVisibleAssistantMessageIndex(array: ChatMessage[] | undefined): number;
22
+ /**
23
+ * Traverse the array from the end and pick the last 'assistant' message among the last group of "assistant" messages where display is true
24
+ * @param array The array of ChatMessage to traverse
25
+ * @returns The index of the last visible assistant message among the last group of "assistant" messages in the array
26
+ */
27
+ lastVisibleAssistantMessageIndex(array: ChatMessage[] | undefined): number;
28
+ /**
29
+ * Format a date string in UTC to a local date string
30
+ * @param value Date string in UTC to format
31
+ * @returns A formatted local date string
32
+ */
33
+ formatDateTime(value: string): string;
34
+ /**
35
+ * Takes a text prompt that may contain placeholders for variables
36
+ * and replaces these placeholders if it finds a match in the given
37
+ * context object.
38
+ *
39
+ * @example
40
+ * const p = "Hello, [[user.name]]! You have [[user.notifications.length]] new notifications.";
41
+ * const context = {
42
+ * user: {
43
+ * name: "Alice",
44
+ * notifications: ["Message from Bob", "Reminder for meeting"]
45
+ * }
46
+ * };
47
+ * const formattedPrompt = formatPrompt(p, context);
48
+ * console.log(formattedPrompt); // Output: "Hello, Alice! You have 2 new notifications."
49
+ */
50
+ static formatPrompt(prompt: string, context: any): string;
51
+ /**
52
+ * Determines a time-based key for a given date to be used for translations or formatting.
53
+ * The key represents a relative time period such as "today", "yesterday", "this week", etc.
54
+ * If the date does not fall into any predefined relative time period, it returns the year as a string.
55
+ *
56
+ * @param date - The date for which the time key is to be determined.
57
+ * @returns A string representing the time key, which can be used for translation or display purposes.
58
+ */
59
+ getTimeKey(date: Date): string;
60
+ /**
61
+ * Get the current locale name.
62
+ * @returns The current locale name or an empty string if not available.
63
+ */
64
+ getCurrentLocaleName(): string;
65
+ static ɵfac: i0.ɵɵFactoryDeclaration<AssistantUtils, never>;
66
+ static ɵprov: i0.ɵɵInjectableDeclaration<AssistantUtils>;
67
+ }