@sinequa/assistant 3.2.3 → 3.3.0-DEV.16

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.
@@ -1,7 +1,7 @@
1
1
  import { EventEmitter, OnChanges, SimpleChanges, ChangeDetectorRef, AfterViewInit, ElementRef } from "@angular/core";
2
- import { PrincipalWebService, Record } from "@sinequa/core/web-services";
2
+ import { PrincipalWebService } from "@sinequa/core/web-services";
3
3
  import { SearchService } from "@sinequa/components/search";
4
- import { ChatContextAttachment, ChatMessage } from "../types";
4
+ import { ChatContextAttachment, ChatMessage, SuggestedAction } from "../types";
5
5
  import { Processor } from "unified";
6
6
  import { Node } from "unist";
7
7
  import { UIService } from "@sinequa/components/utils";
@@ -16,13 +16,14 @@ export declare class ChatMessageComponent implements OnChanges, AfterViewInit {
16
16
  el: ElementRef;
17
17
  message: ChatMessage;
18
18
  conversation: ChatMessage[];
19
+ suggestedActions: SuggestedAction[] | undefined;
19
20
  assistantMessageIcon: string;
20
21
  userMessageIcon: string;
21
22
  streaming: boolean;
22
23
  canEdit: boolean;
23
24
  canRegenerate: boolean;
24
25
  canCopy: boolean;
25
- referenceClicked: EventEmitter<{
26
+ openDocument: EventEmitter<{
26
27
  filename: string;
27
28
  id: string;
28
29
  title: string;
@@ -127,19 +128,20 @@ export declare class ChatMessageComponent implements OnChanges, AfterViewInit {
127
128
  } | undefined;
128
129
  $hasPassages?: boolean | undefined;
129
130
  }>;
131
+ openPreview: EventEmitter<ChatContextAttachment>;
132
+ suggestAction: EventEmitter<SuggestedAction>;
130
133
  edit: EventEmitter<ChatMessage>;
131
134
  regenerate: EventEmitter<ChatMessage>;
132
- openPreview: EventEmitter<ChatContextAttachment>;
133
135
  processor: Processor;
134
136
  references: string[];
135
137
  referenceMap: Map<string, ChatContextAttachment>;
136
138
  showReferences: boolean;
137
139
  collapseProgress: boolean;
140
+ iconSize: number;
138
141
  get name(): string;
139
142
  constructor(searchService: SearchService, ui: UIService, principalService: PrincipalWebService, cdr: ChangeDetectorRef, el: ElementRef);
140
143
  ngOnChanges(changes: SimpleChanges): void;
141
144
  ngAfterViewInit(): void;
142
- openDocument(record: Record): void;
143
145
  /**
144
146
  * This Unified plugin looks a text nodes and replaces any reference in the
145
147
  * form [1], [2.3], etc. with custom nodes of type "chat-reference".
@@ -157,5 +159,5 @@ export declare class ChatMessageComponent implements OnChanges, AfterViewInit {
157
159
  getReferenceMatches(content: string): RegExpMatchArray[];
158
160
  copyToClipboard(text: string): void;
159
161
  static ɵfac: i0.ɵɵFactoryDeclaration<ChatMessageComponent, never>;
160
- static ɵcmp: i0.ɵɵComponentDeclaration<ChatMessageComponent, "sq-chat-message", never, { "message": "message"; "conversation": "conversation"; "assistantMessageIcon": "assistantMessageIcon"; "userMessageIcon": "userMessageIcon"; "streaming": "streaming"; "canEdit": "canEdit"; "canRegenerate": "canRegenerate"; "canCopy": "canCopy"; }, { "referenceClicked": "referenceClicked"; "edit": "edit"; "regenerate": "regenerate"; "openPreview": "openPreview"; }, never, never, true>;
162
+ static ɵcmp: i0.ɵɵComponentDeclaration<ChatMessageComponent, "sq-chat-message", never, { "message": "message"; "conversation": "conversation"; "suggestedActions": "suggestedActions"; "assistantMessageIcon": "assistantMessageIcon"; "userMessageIcon": "userMessageIcon"; "streaming": "streaming"; "canEdit": "canEdit"; "canRegenerate": "canRegenerate"; "canCopy": "canCopy"; }, { "openDocument": "openDocument"; "openPreview": "openPreview"; "suggestAction": "suggestAction"; "edit": "edit"; "regenerate": "regenerate"; }, never, never, true>;
161
163
  }
@@ -5,6 +5,7 @@ import { Subscription } from "rxjs";
5
5
  import { InstanceManagerService } from "../instance-manager.service";
6
6
  import { PrincipalWebService } from "@sinequa/core/web-services";
7
7
  import { LoginService } from "@sinequa/core/login";
8
+ import { AppService } from "@sinequa/core/app-utils";
8
9
  import * as i0 from "@angular/core";
9
10
  export declare class ChatSettingsV3Component implements OnInit, OnDestroy {
10
11
  /** Define the key based on it, the appropriate chatService instance will be returned from instanceManagerService */
@@ -23,6 +24,7 @@ export declare class ChatSettingsV3Component implements OnInit, OnDestroy {
23
24
  loginService: LoginService;
24
25
  instanceManagerService: InstanceManagerService;
25
26
  principalService: PrincipalWebService;
27
+ appService: AppService;
26
28
  ngOnInit(): void;
27
29
  ngOnDestroy(): void;
28
30
  get hasPrompts(): boolean;
@@ -35,6 +37,7 @@ export declare class ChatSettingsV3Component implements OnInit, OnDestroy {
35
37
  private initFunctionsList;
36
38
  /**
37
39
  * Save the new chat config in the chat service and the user preferences
40
+ * If the user has never modified the default values, we need to save the hash of the standard default values, as defined by the admin, in order to properly track changes afterwards.
38
41
  */
39
42
  save(): void;
40
43
  /**
@@ -6,15 +6,12 @@ import { Query } from "@sinequa/core/app-utils";
6
6
  import { PrincipalWebService } from "@sinequa/core/web-services";
7
7
  import { BehaviorSubject, Subscription } from "rxjs";
8
8
  import { ChatService } from "./chat.service";
9
- import { ChatContextAttachment, ChatConfig, ChatMessage, GllmModelDescription, MessageHandler, RawMessage } from "./types";
9
+ import { ChatContextAttachment, ChatConfig, ChatMessage, GllmModelDescription, MessageHandler, RawMessage, SuggestedAction, InitChat } from "./types";
10
10
  import { InstanceManagerService } from "./instance-manager.service";
11
11
  import { WebSocketChatService } from "./websocket-chat.service";
12
12
  import { LoginService } from "@sinequa/core/login";
13
13
  import { RestChatService } from "./rest-chat.service";
14
14
  import * as i0 from "@angular/core";
15
- export interface InitChat {
16
- messages: RawMessage[];
17
- }
18
15
  export declare class ChatComponent extends AbstractFacet implements OnInit, OnChanges, OnDestroy {
19
16
  loginService: LoginService;
20
17
  websocketService: WebSocketChatService;
@@ -946,11 +943,16 @@ export declare class ChatComponent extends AbstractFacet implements OnInit, OnCh
946
943
  messageHandlers: Map<string, MessageHandler<any>>;
947
944
  /** When the assistant answer a user question, automatically scroll down to the bottom of the discussion */
948
945
  automaticScrollToLastResponse: boolean;
946
+ /** A chat discussion that the component should get initialized with it */
949
947
  chat?: InitChat;
948
+ /** Icon to use for the assistant messages */
950
949
  assistantMessageIcon: string;
950
+ /** Icon to use for the user messages */
951
951
  userMessageIcon: string;
952
+ /** Event emitter triggered each time the assistant updates the current chat */
952
953
  data: EventEmitter<ChatMessage[]>;
953
- referenceClicked: EventEmitter<{
954
+ /** Event emitter triggered when the user clicks to open the original document representing the context attachment*/
955
+ openDocument: EventEmitter<{
954
956
  filename: string;
955
957
  id: string;
956
958
  title: string;
@@ -1055,9 +1057,13 @@ export declare class ChatComponent extends AbstractFacet implements OnInit, OnCh
1055
1057
  } | undefined;
1056
1058
  $hasPassages?: boolean | undefined;
1057
1059
  }>;
1060
+ /** Event emitter triggered when the user clicks to open the preview of a document representing the context attachment */
1058
1061
  openPreview: EventEmitter<ChatContextAttachment>;
1062
+ /** Event emitter triggered when the user clicks on a suggested action */
1063
+ suggestAction: EventEmitter<SuggestedAction>;
1064
+ /** Event emitter triggered when the chat is loading new content */
1059
1065
  loading$: EventEmitter<boolean>;
1060
- error: EventEmitter<any>;
1066
+ /** Emits the assistant configuration used when instantiating the component */
1061
1067
  _config: EventEmitter<ChatConfig>;
1062
1068
  messageList?: ElementRef<HTMLUListElement>;
1063
1069
  questionInput?: ElementRef<HTMLTextAreaElement>;
@@ -1083,6 +1089,10 @@ export declare class ChatComponent extends AbstractFacet implements OnInit, OnCh
1083
1089
  ngOnInit(): void;
1084
1090
  ngOnChanges(changes: SimpleChanges): void;
1085
1091
  ngOnDestroy(): void;
1092
+ /**
1093
+ * Instantiate the chat service based on the provided @input protocol
1094
+ * The chat service instance will then be stored in the instanceManagerService with provided @input instanceId as a key
1095
+ */
1086
1096
  instantiateChatService(): void;
1087
1097
  get actions(): Action[];
1088
1098
  private handleChanges;
@@ -1092,8 +1102,7 @@ export declare class ChatComponent extends AbstractFacet implements OnInit, OnCh
1092
1102
  submitQuestion(): void;
1093
1103
  private fetchAnswer;
1094
1104
  /**
1095
- * Given a list of messages, fetch the server for a continuation and updates
1096
- * the list of messages accordingly.
1105
+ * Given a list of messages, the chat endpoint is invoked for a continuation and updates the list of messages accordingly.
1097
1106
  * @param messages
1098
1107
  */
1099
1108
  fetch(messages: ChatMessage[]): void;
@@ -1124,17 +1133,29 @@ export declare class ChatComponent extends AbstractFacet implements OnInit, OnCh
1124
1133
  */
1125
1134
  openChat(messages: RawMessage[], chatId?: string): void;
1126
1135
  /**
1127
- * Reset the chat by clearing the messages and the chat history
1128
- * The question input will be focused after the chat is reset
1136
+ * Reset the chat by clearing the chat history and the UI accordingly
1137
+ * The user input will be cleared
1129
1138
  * The fetch subscription will be terminated
1130
1139
  */
1131
1140
  resetChat(): void;
1132
1141
  onLoadChat(): void;
1133
1142
  terminateFetch(): void;
1143
+ /**
1144
+ * Copy a previous user message of the chat history to the chat user input.
1145
+ * Thus, the user can edit and resubmit the message.
1146
+ * 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.
1147
+ * The assistant will regenerate a new answer based on the updated chat history.
1148
+ * @param index The index of the user's message to edit
1149
+ */
1134
1150
  editMessage(index: number): void;
1151
+ /**
1152
+ * Starting from the provided index, remove all subsequent messages from the chat history and the UI accordingly.
1153
+ * The assistant will regenerate a new answer based on the updated chat history.
1154
+ * @param index The index of the assistant's message to regenerate
1155
+ */
1135
1156
  regenerateMessage(index: number): void;
1136
1157
  onKeyUp(event: KeyboardEvent): void;
1137
1158
  calculateHeight(): void;
1138
1159
  static ɵfac: i0.ɵɵFactoryDeclaration<ChatComponent, never>;
1139
- static ɵcmp: i0.ɵɵComponentDeclaration<ChatComponent, "sq-chat-v3", never, { "instanceId": "instanceId"; "query": "query"; "queryChangeShouldTriggerReload": "queryChangeShouldTriggerReload"; "protocol": "protocol"; "messageHandlers": "messageHandlers"; "automaticScrollToLastResponse": "automaticScrollToLastResponse"; "chat": "chat"; "assistantMessageIcon": "assistantMessageIcon"; "userMessageIcon": "userMessageIcon"; }, { "data": "data"; "referenceClicked": "referenceClicked"; "openPreview": "openPreview"; "loading$": "loading"; "error": "error"; "_config": "config"; }, ["loadingTpl"], never, true>;
1160
+ static ɵcmp: i0.ɵɵComponentDeclaration<ChatComponent, "sq-chat-v3", never, { "instanceId": "instanceId"; "query": "query"; "queryChangeShouldTriggerReload": "queryChangeShouldTriggerReload"; "protocol": "protocol"; "messageHandlers": "messageHandlers"; "automaticScrollToLastResponse": "automaticScrollToLastResponse"; "chat": "chat"; "assistantMessageIcon": "assistantMessageIcon"; "userMessageIcon": "userMessageIcon"; }, { "data": "data"; "openDocument": "openDocument"; "openPreview": "openPreview"; "suggestAction": "suggestAction"; "loading$": "loading"; "_config": "config"; }, ["loadingTpl"], never, true>;
1140
1161
  }
@@ -3,7 +3,7 @@ import { LoginService } from "@sinequa/core/login";
3
3
  import { NotificationsService } from "@sinequa/core/notification";
4
4
  import { AuditWebService, UserSettingsWebService } from "@sinequa/core/web-services";
5
5
  import { BehaviorSubject, Observable } from "rxjs";
6
- import { ChatConfig, ChatMessage, ChatResponse, GllmFunction, GllmModelDescription, SavedChat, SavedChatHistory } from "./types";
6
+ import { ChatConfig, ChatMessage, ChatResponse, ChatUsageMetrics, GllmFunction, GllmModelDescription, Quota, SavedChat, SavedChatHistory, TokenConsumption, UserTokenConsumption } from "./types";
7
7
  import { AppService, Query } from "@sinequa/core/app-utils";
8
8
  import { IntlService } from "@sinequa/core/intl";
9
9
  import { ModalService } from "@sinequa/core/modal";
@@ -29,6 +29,14 @@ export declare abstract class ChatService {
29
29
  savedChats$: BehaviorSubject<SavedChat[]>;
30
30
  /** Emit the saved chat to load */
31
31
  loadSavedChat$: BehaviorSubject<SavedChat | undefined>;
32
+ /** Emit the quota each time the chat is invoked */
33
+ quota$: BehaviorSubject<Quota | undefined>;
34
+ /** Emit the calculated user's token consumption based on the quota */
35
+ userTokenConsumption$: BehaviorSubject<UserTokenConsumption | undefined>;
36
+ /** Emit the chat usage metrics each time the generation of the assistant response is completed */
37
+ chatUsageMetrics$: BehaviorSubject<ChatUsageMetrics | undefined>;
38
+ /** Emit the calculated chat's token consumption based on the chat usage metrics */
39
+ chatTokenConsumption$: BehaviorSubject<TokenConsumption | undefined>;
32
40
  /** Instance ID of the chat service defining the assistant instance */
33
41
  private _chatInstanceId;
34
42
  /** ID of the current chat discussion which is used to update/get/delete it */
@@ -81,12 +89,13 @@ export declare abstract class ChatService {
81
89
  /**
82
90
  * Update the chat config and store its defaultValues in the user preferences
83
91
  * @param config The updated chat config
92
+ * @param hashes The updated hashes to store in the user preferences
84
93
  * @param notify Whether to notify the user about the update
85
94
  * @param successCallback The callback to execute if the update is successful
86
95
  * @param errorCallback The callback to execute if the update fails
87
96
  */
88
97
  updateChatConfig(config: ChatConfig, hashes?: {
89
- "applied-defaultValues-hash": string;
98
+ "applied-defaultValues-hash"?: string;
90
99
  "skipped-defaultValues-hash"?: string;
91
100
  }, notify?: boolean, successCallback?: () => any, errorCallback?: () => any): void;
92
101
  /**
@@ -101,6 +110,19 @@ export declare abstract class ChatService {
101
110
  * Return the list of functions available on the server AND matching enabled functions in the chat config
102
111
  */
103
112
  abstract listFunctions(): Observable<GllmFunction[] | undefined>;
113
+ /**
114
+ * A handler for quota updates each time the chat is invoked.
115
+ * 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.
116
+ * @param quota The updated quota
117
+ * @param propagateError Whether to propagate the error to the caller
118
+ */
119
+ updateQuota(quota: Quota, propagateError?: boolean): void;
120
+ /**
121
+ * A handler for chat usage metrics each time the generation of the assistant response is completed.
122
+ * It emits the chat usage metrics to the chatUsageMetrics$ subject, emits accordingly the updated chat's tokens consumption
123
+ * @param chatUsageMetrics The chat usage metrics
124
+ */
125
+ updateChatUsageMetrics(chatUsageMetrics: ChatUsageMetrics): void;
104
126
  /**
105
127
  * Get the model description for the given (serviceId + modelId)
106
128
  * If a model is not found, an error message is returned
@@ -1,5 +1,4 @@
1
1
  import { EventEmitter, OnDestroy, OnInit } from "@angular/core";
2
- import { AuditWebService } from "@sinequa/core/web-services";
3
2
  import { Subscription, BehaviorSubject } from "rxjs";
4
3
  import { LoginService } from "@sinequa/core/login";
5
4
  import { ModalService } from "@sinequa/core/modal";
@@ -21,7 +20,6 @@ export declare class SavedChatsComponent implements OnInit, OnDestroy {
21
20
  }[]>;
22
21
  loginService: LoginService;
23
22
  instanceManagerService: InstanceManagerService;
24
- auditService: AuditWebService;
25
23
  modalService: ModalService;
26
24
  notificationsService: NotificationsService;
27
25
  ngOnInit(): void;
@@ -0,0 +1,27 @@
1
+ import { OnDestroy, OnInit } from '@angular/core';
2
+ import { Subscription } from 'rxjs';
3
+ import { ChatConfig } from '../types';
4
+ import { LoginService } from '@sinequa/core/login';
5
+ import { InstanceManagerService } from '../instance-manager.service';
6
+ import { ChatService } from '../chat.service';
7
+ import * as i0 from "@angular/core";
8
+ export declare class TokenProgressBarComponent implements OnInit, OnDestroy {
9
+ /** Define the key based on it, the appropriate chatService instance will be returned from instanceManagerService */
10
+ instanceId: string;
11
+ chatService: ChatService;
12
+ config: ChatConfig;
13
+ subscription: Subscription;
14
+ userPercentage?: number;
15
+ userTitle?: string;
16
+ chatPercentage?: number;
17
+ chatTitle?: string;
18
+ loginService: LoginService;
19
+ instanceManagerService: InstanceManagerService;
20
+ ngOnInit(): void;
21
+ ngOnDestroy(): void;
22
+ instantiateChatService(): void;
23
+ onUserTokensConsumption(): void;
24
+ onChatTokensConsumption(): void;
25
+ static ɵfac: i0.ɵɵFactoryDeclaration<TokenProgressBarComponent, never>;
26
+ static ɵcmp: i0.ɵɵComponentDeclaration<TokenProgressBarComponent, "sq-token-progress-bar", never, { "instanceId": "instanceId"; }, {}, never, never, true>;
27
+ }
package/chat/types.d.ts CHANGED
@@ -25,9 +25,11 @@ export interface ChatMessage extends RawMessage {
25
25
  display?: boolean;
26
26
  $progress?: ChatProgress[];
27
27
  $attachment?: ChatContextAttachment[];
28
+ $suggestedAction?: SuggestedAction[];
28
29
  forcedWorkflow?: string;
29
30
  query?: Query;
30
31
  isUserInput?: boolean;
32
+ usageMetrics?: ChatUsageMetrics;
31
33
  [key: string]: any;
32
34
  };
33
35
  }
@@ -83,6 +85,8 @@ export interface GllmModelDescription {
83
85
  serviceId: string;
84
86
  modelId: string;
85
87
  enable: boolean;
88
+ maxGenerationSize: number;
89
+ contextWindowSize: number;
86
90
  }
87
91
  /**
88
92
  * Response of the ListFunctions API
@@ -466,10 +470,16 @@ export declare const chatConfigSchema: z.ZodObject<{
466
470
  }>;
467
471
  globalSettings: z.ZodObject<{
468
472
  disclaimer: z.ZodOptional<z.ZodString>;
473
+ displayUserQuotaConsumption: z.ZodOptional<z.ZodBoolean>;
474
+ displayChatTokensConsumption: z.ZodOptional<z.ZodBoolean>;
469
475
  }, "strip", z.ZodTypeAny, {
470
476
  disclaimer?: string | undefined;
477
+ displayUserQuotaConsumption?: boolean | undefined;
478
+ displayChatTokensConsumption?: boolean | undefined;
471
479
  }, {
472
480
  disclaimer?: string | undefined;
481
+ displayUserQuotaConsumption?: boolean | undefined;
482
+ displayChatTokensConsumption?: boolean | undefined;
473
483
  }>;
474
484
  }, "strip", z.ZodTypeAny, {
475
485
  connectionSettings: {
@@ -520,6 +530,8 @@ export declare const chatConfigSchema: z.ZodObject<{
520
530
  };
521
531
  globalSettings: {
522
532
  disclaimer?: string | undefined;
533
+ displayUserQuotaConsumption?: boolean | undefined;
534
+ displayChatTokensConsumption?: boolean | undefined;
523
535
  };
524
536
  }, {
525
537
  connectionSettings: {
@@ -570,6 +582,8 @@ export declare const chatConfigSchema: z.ZodObject<{
570
582
  };
571
583
  globalSettings: {
572
584
  disclaimer?: string | undefined;
585
+ displayUserQuotaConsumption?: boolean | undefined;
586
+ displayChatTokensConsumption?: boolean | undefined;
573
587
  };
574
588
  }>;
575
589
  export interface ChatConfig extends z.infer<typeof chatConfigSchema> {
@@ -610,9 +624,19 @@ export interface Quota {
610
624
  nextResetUTC: string;
611
625
  maxQuotaReached: boolean;
612
626
  }
627
+ export interface SuggestedAction {
628
+ content: string;
629
+ type: string;
630
+ }
631
+ export interface InitChat {
632
+ messages: RawMessage[];
633
+ }
613
634
  /**
614
635
  * List of events data that can be emitted by the websocket chat endpoint
615
636
  */
637
+ export declare type SuggestedActionsEvent = {
638
+ suggestedActions: SuggestedAction[];
639
+ };
616
640
  export declare type QuotaEvent = {
617
641
  quota: Quota;
618
642
  };
@@ -643,6 +667,7 @@ export declare type HistoryEvent = {
643
667
  */
644
668
  export declare type HttpChatResponse = {
645
669
  quota: Quota;
670
+ suggestedActions: SuggestedAction[];
646
671
  debug: any;
647
672
  context: {
648
673
  content: string;
@@ -652,6 +677,18 @@ export declare type HttpChatResponse = {
652
677
  history: RawMessage[];
653
678
  executionTime: string;
654
679
  };
680
+ export interface TokenConsumption {
681
+ percentage: number;
682
+ }
683
+ export interface UserTokenConsumption extends TokenConsumption {
684
+ nextResetDate: string;
685
+ }
686
+ export interface ChatUsageMetrics {
687
+ totalTokenCount: number;
688
+ promptTokenCount: number;
689
+ completionTokenCount: number;
690
+ tokenizerType: string;
691
+ }
655
692
  export declare type MessageHandler<T> = {
656
693
  handler: (data: T) => void;
657
694
  isGlobalHandler: boolean;
@@ -16,6 +16,7 @@ export declare class WebSocketChatService extends ChatService {
16
16
  private _content;
17
17
  private _executionTime;
18
18
  private _attachments;
19
+ private _suggestedActions;
19
20
  signalRService: SignalRWebService;
20
21
  authenticationService: AuthenticationService;
21
22
  constructor();