@fr-data-fabric/chatbot-api-nest 0.0.2 → 0.0.4

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 (51) hide show
  1. package/dist/chatbot-api.module.d.ts +12 -11
  2. package/dist/chatbot-api.module.js +7 -7
  3. package/dist/chatbot-api.module.js.map +1 -1
  4. package/dist/domain/entities/ChatEntity.d.ts +3 -3
  5. package/dist/domain/entities/ConversationEntity.d.ts +2 -2
  6. package/dist/domain/interfaces/ChatRepository.d.ts +1 -1
  7. package/dist/domain/interfaces/ConversationRepository.d.ts +1 -1
  8. package/dist/domain/use-cases/_common.d.ts +3 -3
  9. package/dist/domain/use-cases/chats/GetChatCompletionUC.d.ts +8 -8
  10. package/dist/domain/use-cases/chats/GetChatCompletionUC.js.map +1 -1
  11. package/dist/domain/use-cases/chats/SendChatUC.d.ts +16 -16
  12. package/dist/domain/use-cases/chats/SendChatUC.js +3 -0
  13. package/dist/domain/use-cases/chats/SendChatUC.js.map +1 -1
  14. package/dist/domain/use-cases/chats/chat.types.d.ts +1 -1
  15. package/dist/domain/use-cases/conversations/CreateConversationUC.d.ts +5 -4
  16. package/dist/domain/use-cases/conversations/CreateConversationUC.js.map +1 -1
  17. package/dist/domain/use-cases/conversations/DeleteConversationUC.d.ts +7 -6
  18. package/dist/domain/use-cases/conversations/DeleteConversationUC.js +2 -2
  19. package/dist/domain/use-cases/conversations/DeleteConversationUC.js.map +1 -1
  20. package/dist/domain/use-cases/conversations/GenerateConversationTitleUC.d.ts +9 -8
  21. package/dist/domain/use-cases/conversations/GenerateConversationTitleUC.js +4 -4
  22. package/dist/domain/use-cases/conversations/GenerateConversationTitleUC.js.map +1 -1
  23. package/dist/domain/use-cases/conversations/GetConversationUC.d.ts +5 -4
  24. package/dist/domain/use-cases/conversations/GetConversationUC.js.map +1 -1
  25. package/dist/domain/use-cases/conversations/GetConversationsUC.d.ts +5 -4
  26. package/dist/domain/use-cases/conversations/GetConversationsUC.js +1 -1
  27. package/dist/domain/use-cases/conversations/GetConversationsUC.js.map +1 -1
  28. package/dist/domain/use-cases/conversations/UpdateConversationUC.d.ts +7 -6
  29. package/dist/domain/use-cases/conversations/UpdateConversationUC.js +2 -2
  30. package/dist/domain/use-cases/conversations/UpdateConversationUC.js.map +1 -1
  31. package/dist/inputs/controllers/ChatsController.d.ts +3 -3
  32. package/dist/inputs/controllers/ChatsController.js +1 -1
  33. package/dist/inputs/controllers/ChatsController.js.map +1 -1
  34. package/dist/inputs/resolvers/ChatsResolver.d.ts +1 -1
  35. package/dist/inputs/resolvers/ConversationsResolver.d.ts +15 -15
  36. package/dist/inputs/resolvers/ConversationsResolver.js +7 -7
  37. package/dist/inputs/resolvers/ConversationsResolver.js.map +1 -1
  38. package/dist/tsconfig.tsbuildinfo +1 -1
  39. package/package.json +4 -3
  40. package/src/chatbot-api.module.ts +9 -6
  41. package/src/domain/use-cases/_common.ts +2 -2
  42. package/src/domain/use-cases/chats/GetChatCompletionUC.ts +7 -3
  43. package/src/domain/use-cases/chats/SendChatUC.ts +14 -5
  44. package/src/domain/use-cases/conversations/CreateConversationUC.ts +3 -2
  45. package/src/domain/use-cases/conversations/DeleteConversationUC.ts +3 -2
  46. package/src/domain/use-cases/conversations/GenerateConversationTitleUC.ts +6 -2
  47. package/src/domain/use-cases/conversations/GetConversationUC.ts +5 -2
  48. package/src/domain/use-cases/conversations/GetConversationsUC.ts +3 -2
  49. package/src/domain/use-cases/conversations/UpdateConversationUC.ts +6 -2
  50. package/src/inputs/controllers/ChatsController.ts +1 -1
  51. package/src/inputs/resolvers/ConversationsResolver.ts +3 -3
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@fr-data-fabric/chatbot-api-nest",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "main": "dist/index.js",
5
5
  "scripts": {
6
- "build": "tsc -p tsconfig.json"
6
+ "build": "tsc -p tsconfig.json && tsc-alias -p tsconfig.json"
7
7
  },
8
8
  "author": "PM Data Fabric",
9
9
  "license": "Apache-2.0",
@@ -17,7 +17,8 @@
17
17
  "rxjs": "^7.8.2"
18
18
  },
19
19
  "devDependencies": {
20
- "@types/express": "^5.0.6"
20
+ "@types/express": "^5.0.6",
21
+ "tsc-alias": "^1.8.16"
21
22
  },
22
23
  "publishConfig": {
23
24
  "access": "public"
@@ -1,3 +1,4 @@
1
+ import { UserEntity } from '@domain/entities/UserEntity';
1
2
  import {
2
3
  CONVERSATION_REPOSITORY,
3
4
  ConversationRepository,
@@ -23,12 +24,12 @@ import { ChatsController } from 'src/inputs/controllers/ChatsController';
23
24
  import { GetChatsResolver } from 'src/inputs/resolvers/ChatsResolver';
24
25
  import { GetConversationsResolver } from 'src/inputs/resolvers/ConversationsResolver';
25
26
 
26
- export type ChatbotApiModuleOptions = {
27
+ export type ChatbotApiModuleOptions<TUser extends UserEntity> = {
27
28
  useCases: {
28
- getConversation: Type<IGetConversationUC>;
29
- getConversations: Type<IGetConversationsUC>;
30
- createConversation: Type<ICreateConversationUC>;
31
- sendChat: Type<SendChatUC<never>>;
29
+ getConversation: Type<IGetConversationUC<TUser>>;
30
+ getConversations: Type<IGetConversationsUC<TUser>>;
31
+ createConversation: Type<ICreateConversationUC<TUser>>;
32
+ sendChat: Type<SendChatUC<never, TUser>>;
32
33
  };
33
34
  conversationRepository: Type<ConversationRepository>;
34
35
  gql: {
@@ -43,7 +44,9 @@ export type ChatbotApiModuleOptions = {
43
44
 
44
45
  @Module({})
45
46
  export class ChatbotApiModule {
46
- static register(options: ChatbotApiModuleOptions): DynamicModule {
47
+ static register<TUser extends UserEntity>(
48
+ options: ChatbotApiModuleOptions<TUser>,
49
+ ): DynamicModule {
47
50
  return {
48
51
  module: ChatbotApiModule,
49
52
  providers: [
@@ -1,9 +1,9 @@
1
1
  import { UserEntity } from '@domain/entities/UserEntity';
2
2
  import { Field, ID, InputType, Int } from '@nestjs/graphql';
3
3
 
4
- export type UCInput<Input> = {
4
+ export type UCInput<Input, TUser extends UserEntity> = {
5
5
  input: Input;
6
- currentUser: UserEntity;
6
+ currentUser?: TUser;
7
7
  };
8
8
 
9
9
  @InputType()
@@ -17,19 +17,23 @@ import {
17
17
  } from 'langchain';
18
18
  import { Observable } from 'rxjs';
19
19
 
20
- export type GetChatCompletionInput<AvailableTools extends AvailableTool[]> = {
20
+ export type GetChatCompletionInput<
21
+ AvailableTools extends AvailableTool[],
22
+ TUser extends UserEntity,
23
+ > = {
21
24
  message: string;
22
25
  previousMessages: { role: 'user' | 'assistant'; content: string }[];
23
26
  conversation: ConversationEntity;
24
27
  runId: string;
25
28
  tools?: AvailableTools;
26
29
  documents: DocumentEntity[];
27
- currentUser: UserEntity;
30
+ currentUser: TUser;
28
31
  model?: string;
29
32
  };
30
33
 
31
34
  export abstract class GetChatCompletionUC<
32
35
  AvailableTools extends AvailableTool[],
36
+ TUser extends UserEntity,
33
37
  > {
34
38
  abstract getTools(
35
39
  toolOptions: ToolOptions,
@@ -52,7 +56,7 @@ export abstract class GetChatCompletionUC<
52
56
  currentUser: UserEntity,
53
57
  ): Promise<{ content: string; id: string }[]>;
54
58
 
55
- execute(input: GetChatCompletionInput<AvailableTools>) {
59
+ execute(input: GetChatCompletionInput<AvailableTools, TUser>) {
56
60
  return new Observable<StreamEvents<AvailableTools>>((observer) => {
57
61
  const model = this.getLLM({
58
62
  model: input.model,
@@ -50,17 +50,23 @@ export class SendMessageInput<AvailableTools extends AvailableTool[]> {
50
50
 
51
51
  export const SEND_CHAT_UC = 'SendChatUC';
52
52
 
53
- export abstract class SendChatUC<AvailableTools extends AvailableTool[]> {
53
+ export abstract class SendChatUC<
54
+ AvailableTools extends AvailableTool[],
55
+ TUser extends UserEntity,
56
+ > {
54
57
  constructor(
55
- private readonly getConversationUC: IGetConversationUC,
58
+ private readonly getConversationUC: IGetConversationUC<TUser>,
56
59
  private readonly chatRepository: ChatRepository,
57
60
  private readonly eventEmitter: EventEmitter2,
58
- private readonly getChatCompletionUC: GetChatCompletionUC<AvailableTools>,
61
+ private readonly getChatCompletionUC: GetChatCompletionUC<
62
+ AvailableTools,
63
+ TUser
64
+ >,
59
65
  ) {}
60
66
 
61
67
  abstract getDocuments(
62
68
  documentIds: string[],
63
- currentUser: UserEntity,
69
+ currentUser: TUser,
64
70
  ): Promise<DocumentEntity[]>;
65
71
 
66
72
  abstract createChatEntity(
@@ -73,7 +79,10 @@ export abstract class SendChatUC<AvailableTools extends AvailableTool[]> {
73
79
  async execute({
74
80
  input,
75
81
  currentUser,
76
- }: UCInput<SendMessageInput<AvailableTools>>) {
82
+ }: UCInput<SendMessageInput<AvailableTools>, TUser>) {
83
+ if (!currentUser) {
84
+ throw new Error('currentUser is required');
85
+ }
77
86
  const { conversationId, content, selectedTools, documentIds, model } =
78
87
  input;
79
88
  const conversation = await this.getConversationUC.execute({
@@ -1,7 +1,8 @@
1
1
  import { ConversationEntity } from '@domain/entities/ConversationEntity';
2
+ import { UserEntity } from '@domain/entities/UserEntity';
2
3
  import { UCInput } from '@domain/use-cases/_common';
3
4
 
4
5
  export const CREATE_CONVERSATION_UC = 'CreateConversationUC';
5
- export interface ICreateConversationUC {
6
- execute(input: UCInput<undefined>): Promise<ConversationEntity>;
6
+ export interface ICreateConversationUC<TUser extends UserEntity> {
7
+ execute(input: UCInput<undefined, TUser>): Promise<ConversationEntity>;
7
8
  }
@@ -1,4 +1,5 @@
1
1
  import { ConversationEntity } from '@domain/entities/ConversationEntity';
2
+ import { UserEntity } from '@domain/entities/UserEntity';
2
3
  import type { ConversationRepository } from '@domain/interfaces/ConversationRepository';
3
4
  import { CONVERSATION_REPOSITORY } from '@domain/interfaces/ConversationRepository';
4
5
  import { DeleteByIdInput, UCInput } from '@domain/use-cases/_common';
@@ -12,13 +13,13 @@ export class DeleteConversationUC {
12
13
  @Inject(CONVERSATION_REPOSITORY)
13
14
  private readonly conversationRepository: ConversationRepository,
14
15
  @Inject(GET_CONVERSATION_UC)
15
- private readonly getConversationUC: IGetConversationUC,
16
+ private readonly getConversationUC: IGetConversationUC<UserEntity>,
16
17
  ) {}
17
18
 
18
19
  async execute({
19
20
  input,
20
21
  currentUser,
21
- }: UCInput<DeleteByIdInput>): Promise<ConversationEntity> {
22
+ }: UCInput<DeleteByIdInput, UserEntity>): Promise<ConversationEntity> {
22
23
  const conversation = await this.getConversationUC.execute({
23
24
  input: { id: input.id },
24
25
  currentUser,
@@ -1,4 +1,5 @@
1
1
  import { ConversationEntity } from '@domain/entities/ConversationEntity';
2
+ import { UserEntity } from '@domain/entities/UserEntity';
2
3
  import type { ConversationRepository } from '@domain/interfaces/ConversationRepository';
3
4
  import { CONVERSATION_REPOSITORY } from '@domain/interfaces/ConversationRepository';
4
5
  import type { LLMService } from '@domain/interfaces/LLMService';
@@ -28,7 +29,7 @@ export class GenerateConversationTitleUC {
28
29
  @Inject(PROMPT_SERVICE)
29
30
  private readonly promptService: PromptService,
30
31
  @Inject(GET_CONVERSATION_UC)
31
- private readonly getConversationUC: IGetConversationUC,
32
+ private readonly getConversationUC: IGetConversationUC<UserEntity>,
32
33
  @Inject(CONVERSATION_REPOSITORY)
33
34
  private readonly conversationRepository: ConversationRepository,
34
35
  ) {}
@@ -36,7 +37,10 @@ export class GenerateConversationTitleUC {
36
37
  async execute({
37
38
  input,
38
39
  currentUser,
39
- }: UCInput<GenerateConversationTitleInput>): Promise<ConversationEntity> {
40
+ }: UCInput<
41
+ GenerateConversationTitleInput,
42
+ UserEntity
43
+ >): Promise<ConversationEntity> {
40
44
  const conversation = await this.getConversationUC.execute({
41
45
  currentUser,
42
46
  input: { id: input.conversationId },
@@ -1,4 +1,5 @@
1
1
  import { ConversationEntity } from '@domain/entities/ConversationEntity';
2
+ import { UserEntity } from '@domain/entities/UserEntity';
2
3
  import { UCInput } from '@domain/use-cases/_common';
3
4
  import { Field, ID, InputType } from '@nestjs/graphql';
4
5
 
@@ -13,6 +14,8 @@ export class GetConversationInput {
13
14
 
14
15
  export const GET_CONVERSATION_UC = 'GetConversationUC';
15
16
 
16
- export interface IGetConversationUC {
17
- execute(input: UCInput<GetConversationInput>): Promise<ConversationEntity>;
17
+ export interface IGetConversationUC<TUser extends UserEntity> {
18
+ execute(
19
+ input: UCInput<GetConversationInput, TUser>,
20
+ ): Promise<ConversationEntity>;
18
21
  }
@@ -1,4 +1,5 @@
1
1
  import { ConversationEntity } from '@domain/entities/ConversationEntity';
2
+ import { UserEntity } from '@domain/entities/UserEntity';
2
3
  import {
3
4
  PaginatedInput,
4
5
  PaginatedOutput,
@@ -14,8 +15,8 @@ export class GetConversationsInput extends PaginatedInput {
14
15
 
15
16
  export const GET_CONVERSATIONS_UC = 'GetConversationsUC';
16
17
 
17
- export interface IGetConversationsUC {
18
+ export interface IGetConversationsUC<TUser extends UserEntity> {
18
19
  execute(
19
- input: UCInput<GetConversationsInput>,
20
+ input: UCInput<GetConversationsInput, TUser>,
20
21
  ): Promise<PaginatedOutput<ConversationEntity>>;
21
22
  }
@@ -1,4 +1,5 @@
1
1
  import { ConversationEntity } from '@domain/entities/ConversationEntity';
2
+ import { UserEntity } from '@domain/entities/UserEntity';
2
3
  import type { ConversationRepository } from '@domain/interfaces/ConversationRepository';
3
4
  import { CONVERSATION_REPOSITORY } from '@domain/interfaces/ConversationRepository';
4
5
  import { UCInput } from '@domain/use-cases/_common';
@@ -25,13 +26,16 @@ export class UpdateConversationUC {
25
26
  @Inject(CONVERSATION_REPOSITORY)
26
27
  private readonly conversationRepository: ConversationRepository,
27
28
  @Inject(GET_CONVERSATION_UC)
28
- private readonly getConversationUC: IGetConversationUC,
29
+ private readonly getConversationUC: IGetConversationUC<UserEntity>,
29
30
  ) {}
30
31
 
31
32
  async execute({
32
33
  input,
33
34
  currentUser,
34
- }: UCInput<UpdateConversationInput>): Promise<ConversationEntity> {
35
+ }: UCInput<
36
+ UpdateConversationInput,
37
+ UserEntity
38
+ >): Promise<ConversationEntity> {
35
39
  const conversation = await this.getConversationUC.execute({
36
40
  input: { id: input.id },
37
41
  currentUser,
@@ -12,7 +12,7 @@ import { CurrentUserRest } from 'src/inputs/controllers/_common/CurrentUserRest'
12
12
  export class ChatsController {
13
13
  constructor(
14
14
  @Inject(SEND_CHAT_UC)
15
- private readonly sendChatUC: SendChatUC<never>,
15
+ private readonly sendChatUC: SendChatUC<never, UserEntity>,
16
16
  ) {}
17
17
 
18
18
  @Post('/')
@@ -48,11 +48,11 @@ export function GetConversationsResolver(
48
48
  class ConversationsResolver {
49
49
  constructor(
50
50
  @Inject(GET_CONVERSATIONS_UC)
51
- readonly getConversationsUC: IGetConversationsUC,
51
+ readonly getConversationsUC: IGetConversationsUC<UserEntity>,
52
52
  @Inject(GET_CONVERSATION_UC)
53
- readonly getConversationUC: IGetConversationUC,
53
+ readonly getConversationUC: IGetConversationUC<UserEntity>,
54
54
  @Inject(CREATE_CONVERSATION_UC)
55
- readonly createConversationUC: ICreateConversationUC,
55
+ readonly createConversationUC: ICreateConversationUC<UserEntity>,
56
56
  readonly updateConversationUC: UpdateConversationUC,
57
57
  readonly deleteConversationUC: DeleteConversationUC,
58
58
  readonly generateConversationTitleUC: GenerateConversationTitleUC,