@fr-data-fabric/chatbot-api-nest 0.0.1
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.
- package/dist/chatbot-api.module.d.ts +27 -0
- package/dist/chatbot-api.module.js +63 -0
- package/dist/chatbot-api.module.js.map +1 -0
- package/dist/domain/entities/ChatEntity.d.ts +11 -0
- package/dist/domain/entities/ChatEntity.js +3 -0
- package/dist/domain/entities/ChatEntity.js.map +1 -0
- package/dist/domain/entities/ChatSourceEntity.d.ts +6 -0
- package/dist/domain/entities/ChatSourceEntity.js +3 -0
- package/dist/domain/entities/ChatSourceEntity.js.map +1 -0
- package/dist/domain/entities/ChatTextContentEntity.d.ts +4 -0
- package/dist/domain/entities/ChatTextContentEntity.js +3 -0
- package/dist/domain/entities/ChatTextContentEntity.js.map +1 -0
- package/dist/domain/entities/ConversationEntity.d.ts +9 -0
- package/dist/domain/entities/ConversationEntity.js +3 -0
- package/dist/domain/entities/ConversationEntity.js.map +1 -0
- package/dist/domain/entities/DocumentEntity.d.ts +3 -0
- package/dist/domain/entities/DocumentEntity.js +3 -0
- package/dist/domain/entities/DocumentEntity.js.map +1 -0
- package/dist/domain/entities/ToolUseEntity.d.ts +6 -0
- package/dist/domain/entities/ToolUseEntity.js +3 -0
- package/dist/domain/entities/ToolUseEntity.js.map +1 -0
- package/dist/domain/entities/UserEntity.d.ts +3 -0
- package/dist/domain/entities/UserEntity.js +3 -0
- package/dist/domain/entities/UserEntity.js.map +1 -0
- package/dist/domain/interfaces/ChatRepository.d.ts +5 -0
- package/dist/domain/interfaces/ChatRepository.js +5 -0
- package/dist/domain/interfaces/ChatRepository.js.map +1 -0
- package/dist/domain/interfaces/ConversationRepository.d.ts +6 -0
- package/dist/domain/interfaces/ConversationRepository.js +5 -0
- package/dist/domain/interfaces/ConversationRepository.js.map +1 -0
- package/dist/domain/interfaces/LLMService.d.ts +13 -0
- package/dist/domain/interfaces/LLMService.js +5 -0
- package/dist/domain/interfaces/LLMService.js.map +1 -0
- package/dist/domain/interfaces/PromptService.d.ts +8 -0
- package/dist/domain/interfaces/PromptService.js +5 -0
- package/dist/domain/interfaces/PromptService.js.map +1 -0
- package/dist/domain/use-cases/_common.d.ts +17 -0
- package/dist/domain/use-cases/_common.js +41 -0
- package/dist/domain/use-cases/_common.js.map +1 -0
- package/dist/domain/use-cases/chats/GetChatCompletionUC.d.ts +28 -0
- package/dist/domain/use-cases/chats/GetChatCompletionUC.js +83 -0
- package/dist/domain/use-cases/chats/GetChatCompletionUC.js.map +1 -0
- package/dist/domain/use-cases/chats/SendChatUC.d.ts +35 -0
- package/dist/domain/use-cases/chats/SendChatUC.js +166 -0
- package/dist/domain/use-cases/chats/SendChatUC.js.map +1 -0
- package/dist/domain/use-cases/chats/chat.types.d.ts +54 -0
- package/dist/domain/use-cases/chats/chat.types.js +3 -0
- package/dist/domain/use-cases/chats/chat.types.js.map +1 -0
- package/dist/domain/use-cases/conversations/CreateConversationUC.d.ts +6 -0
- package/dist/domain/use-cases/conversations/CreateConversationUC.js +5 -0
- package/dist/domain/use-cases/conversations/CreateConversationUC.js.map +1 -0
- package/dist/domain/use-cases/conversations/DeleteConversationUC.d.ts +10 -0
- package/dist/domain/use-cases/conversations/DeleteConversationUC.js +41 -0
- package/dist/domain/use-cases/conversations/DeleteConversationUC.js.map +1 -0
- package/dist/domain/use-cases/conversations/GenerateConversationTitleUC.d.ts +18 -0
- package/dist/domain/use-cases/conversations/GenerateConversationTitleUC.js +80 -0
- package/dist/domain/use-cases/conversations/GenerateConversationTitleUC.js.map +1 -0
- package/dist/domain/use-cases/conversations/GetConversationUC.d.ts +10 -0
- package/dist/domain/use-cases/conversations/GetConversationUC.js +31 -0
- package/dist/domain/use-cases/conversations/GetConversationUC.js.map +1 -0
- package/dist/domain/use-cases/conversations/GetConversationsUC.d.ts +9 -0
- package/dist/domain/use-cases/conversations/GetConversationsUC.js +27 -0
- package/dist/domain/use-cases/conversations/GetConversationsUC.js.map +1 -0
- package/dist/domain/use-cases/conversations/UpdateConversationUC.d.ts +15 -0
- package/dist/domain/use-cases/conversations/UpdateConversationUC.js +74 -0
- package/dist/domain/use-cases/conversations/UpdateConversationUC.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +18 -0
- package/dist/index.js.map +1 -0
- package/dist/inputs/controllers/ChatsController.d.ts +8 -0
- package/dist/inputs/controllers/ChatsController.js +62 -0
- package/dist/inputs/controllers/ChatsController.js.map +1 -0
- package/dist/inputs/controllers/_common/CurrentUserRest.d.ts +1 -0
- package/dist/inputs/controllers/_common/CurrentUserRest.js +9 -0
- package/dist/inputs/controllers/_common/CurrentUserRest.js.map +1 -0
- package/dist/inputs/resolvers/ChatsResolver.d.ts +9 -0
- package/dist/inputs/resolvers/ChatsResolver.js +57 -0
- package/dist/inputs/resolvers/ChatsResolver.js.map +1 -0
- package/dist/inputs/resolvers/ConversationsResolver.d.ts +34 -0
- package/dist/inputs/resolvers/ConversationsResolver.js +170 -0
- package/dist/inputs/resolvers/ConversationsResolver.js.map +1 -0
- package/dist/inputs/resolvers/_common/CurrentUserGql.d.ts +1 -0
- package/dist/inputs/resolvers/_common/CurrentUserGql.js +10 -0
- package/dist/inputs/resolvers/_common/CurrentUserGql.js.map +1 -0
- package/dist/inputs/resolvers/_common/GqlPaginatedOutput.d.ts +8 -0
- package/dist/inputs/resolvers/_common/GqlPaginatedOutput.js +37 -0
- package/dist/inputs/resolvers/_common/GqlPaginatedOutput.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/docs/entities.excalidraw.svg +2 -0
- package/package.json +25 -0
- package/src/chatbot-api.module.ts +90 -0
- package/src/domain/entities/ChatEntity.ts +13 -0
- package/src/domain/entities/ChatSourceEntity.ts +6 -0
- package/src/domain/entities/ChatTextContentEntity.ts +4 -0
- package/src/domain/entities/ConversationEntity.ts +10 -0
- package/src/domain/entities/DocumentEntity.ts +3 -0
- package/src/domain/entities/ToolUseEntity.ts +6 -0
- package/src/domain/entities/UserEntity.ts +3 -0
- package/src/domain/interfaces/ChatRepository.ts +7 -0
- package/src/domain/interfaces/ConversationRepository.ts +8 -0
- package/src/domain/interfaces/LLMService.ts +15 -0
- package/src/domain/interfaces/PromptService.ts +10 -0
- package/src/domain/use-cases/_common.ts +28 -0
- package/src/domain/use-cases/chats/GetChatCompletionUC.ts +126 -0
- package/src/domain/use-cases/chats/SendChatUC.ts +202 -0
- package/src/domain/use-cases/chats/chat.types.ts +51 -0
- package/src/domain/use-cases/conversations/CreateConversationUC.ts +7 -0
- package/src/domain/use-cases/conversations/DeleteConversationUC.ts +29 -0
- package/src/domain/use-cases/conversations/GenerateConversationTitleUC.ts +69 -0
- package/src/domain/use-cases/conversations/GetConversationUC.ts +18 -0
- package/src/domain/use-cases/conversations/GetConversationsUC.ts +21 -0
- package/src/domain/use-cases/conversations/UpdateConversationUC.ts +54 -0
- package/src/index.ts +1 -0
- package/src/inputs/controllers/ChatsController.ts +47 -0
- package/src/inputs/controllers/_common/CurrentUserRest.ts +10 -0
- package/src/inputs/resolvers/ChatsResolver.ts +40 -0
- package/src/inputs/resolvers/ConversationsResolver.ts +149 -0
- package/src/inputs/resolvers/_common/CurrentUserGql.ts +11 -0
- package/src/inputs/resolvers/_common/GqlPaginatedOutput.ts +25 -0
- package/tsconfig.json +28 -0
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.SendChatUC = exports.SEND_CHAT_UC = exports.SendMessageInput = void 0;
|
|
13
|
+
const class_validator_1 = require("class-validator");
|
|
14
|
+
const rxjs_1 = require("rxjs");
|
|
15
|
+
class SendMessageInput {
|
|
16
|
+
conversationId;
|
|
17
|
+
content;
|
|
18
|
+
selectedTools;
|
|
19
|
+
documentIds;
|
|
20
|
+
model;
|
|
21
|
+
}
|
|
22
|
+
exports.SendMessageInput = SendMessageInput;
|
|
23
|
+
__decorate([
|
|
24
|
+
(0, class_validator_1.IsString)(),
|
|
25
|
+
(0, class_validator_1.IsNotEmpty)(),
|
|
26
|
+
__metadata("design:type", String)
|
|
27
|
+
], SendMessageInput.prototype, "conversationId", void 0);
|
|
28
|
+
__decorate([
|
|
29
|
+
(0, class_validator_1.IsString)(),
|
|
30
|
+
(0, class_validator_1.IsNotEmpty)(),
|
|
31
|
+
__metadata("design:type", String)
|
|
32
|
+
], SendMessageInput.prototype, "content", void 0);
|
|
33
|
+
__decorate([
|
|
34
|
+
(0, class_validator_1.IsArray)(),
|
|
35
|
+
(0, class_validator_1.ValidateNested)({ each: true }),
|
|
36
|
+
(0, class_validator_1.IsOptional)(),
|
|
37
|
+
__metadata("design:type", Object)
|
|
38
|
+
], SendMessageInput.prototype, "selectedTools", void 0);
|
|
39
|
+
__decorate([
|
|
40
|
+
(0, class_validator_1.IsArray)(),
|
|
41
|
+
(0, class_validator_1.IsString)({ each: true }),
|
|
42
|
+
(0, class_validator_1.IsOptional)(),
|
|
43
|
+
__metadata("design:type", Array)
|
|
44
|
+
], SendMessageInput.prototype, "documentIds", void 0);
|
|
45
|
+
__decorate([
|
|
46
|
+
(0, class_validator_1.IsString)(),
|
|
47
|
+
(0, class_validator_1.IsNotEmpty)(),
|
|
48
|
+
(0, class_validator_1.IsOptional)(),
|
|
49
|
+
__metadata("design:type", String)
|
|
50
|
+
], SendMessageInput.prototype, "model", void 0);
|
|
51
|
+
exports.SEND_CHAT_UC = 'SendChatUC';
|
|
52
|
+
class SendChatUC {
|
|
53
|
+
getConversationUC;
|
|
54
|
+
chatRepository;
|
|
55
|
+
eventEmitter;
|
|
56
|
+
getChatCompletionUC;
|
|
57
|
+
constructor(getConversationUC, chatRepository, eventEmitter, getChatCompletionUC) {
|
|
58
|
+
this.getConversationUC = getConversationUC;
|
|
59
|
+
this.chatRepository = chatRepository;
|
|
60
|
+
this.eventEmitter = eventEmitter;
|
|
61
|
+
this.getChatCompletionUC = getChatCompletionUC;
|
|
62
|
+
}
|
|
63
|
+
async execute({ input, currentUser, }) {
|
|
64
|
+
const { conversationId, content, selectedTools, documentIds, model } = input;
|
|
65
|
+
const conversation = await this.getConversationUC.execute({
|
|
66
|
+
input: { id: conversationId },
|
|
67
|
+
currentUser,
|
|
68
|
+
});
|
|
69
|
+
let documents = [];
|
|
70
|
+
if (documentIds && documentIds.length) {
|
|
71
|
+
documents = await this.getDocuments(documentIds, currentUser);
|
|
72
|
+
if (documents.length !== documentIds.length) {
|
|
73
|
+
throw new Error('Some documents not found');
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
const userMessage = this.createChatEntity('user', input.content, conversation, documents);
|
|
77
|
+
const assistantMessage = this.createChatEntity('assistant', '', conversation);
|
|
78
|
+
await this.chatRepository.save(userMessage);
|
|
79
|
+
await this.chatRepository.save(assistantMessage);
|
|
80
|
+
this.eventEmitter.emit('message.new', userMessage);
|
|
81
|
+
const stream = this.getChatCompletionUC.execute({
|
|
82
|
+
message: content,
|
|
83
|
+
previousMessages: [],
|
|
84
|
+
conversation,
|
|
85
|
+
runId: assistantMessage.id,
|
|
86
|
+
tools: selectedTools,
|
|
87
|
+
documents,
|
|
88
|
+
currentUser,
|
|
89
|
+
model,
|
|
90
|
+
});
|
|
91
|
+
const tools = new Map();
|
|
92
|
+
const sources = [];
|
|
93
|
+
const chatCompletion = [];
|
|
94
|
+
let textContent = '';
|
|
95
|
+
let order = 0;
|
|
96
|
+
return new rxjs_1.Observable((observer) => {
|
|
97
|
+
observer.next({ event: 'user_message_id', id: userMessage.id });
|
|
98
|
+
observer.next({ event: 'assistant_message_id', id: assistantMessage.id });
|
|
99
|
+
stream.subscribe({
|
|
100
|
+
next: (event) => {
|
|
101
|
+
observer.next(event);
|
|
102
|
+
if (event.event === 'tool_start') {
|
|
103
|
+
if (textContent) {
|
|
104
|
+
chatCompletion.push({
|
|
105
|
+
content: textContent,
|
|
106
|
+
order: order++,
|
|
107
|
+
});
|
|
108
|
+
textContent = '';
|
|
109
|
+
}
|
|
110
|
+
const tool = {
|
|
111
|
+
name: event.name,
|
|
112
|
+
input: JSON.stringify(event.input),
|
|
113
|
+
output: null,
|
|
114
|
+
order: order++,
|
|
115
|
+
};
|
|
116
|
+
tools.set(event.id, tool);
|
|
117
|
+
}
|
|
118
|
+
else if (event.event === 'tool_stream_start') {
|
|
119
|
+
// Do nothing at the moment
|
|
120
|
+
}
|
|
121
|
+
else if (event.event === 'tool_end') {
|
|
122
|
+
if (!tools.has(event.id)) {
|
|
123
|
+
// This should never happen
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
const tool = tools.get(event.id);
|
|
127
|
+
if (tool) {
|
|
128
|
+
tool.input = event.input;
|
|
129
|
+
tool.output = JSON.stringify(event.output);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
else if (event.event == 'sources_add') {
|
|
134
|
+
sources.push(...event.sources.map((s) => ({
|
|
135
|
+
content: s.content,
|
|
136
|
+
link: s.link,
|
|
137
|
+
title: s.title,
|
|
138
|
+
index: s.index,
|
|
139
|
+
})));
|
|
140
|
+
}
|
|
141
|
+
else if (event.event === 'chat_stream') {
|
|
142
|
+
textContent += event.content;
|
|
143
|
+
}
|
|
144
|
+
},
|
|
145
|
+
complete: () => {
|
|
146
|
+
void (async () => {
|
|
147
|
+
if (textContent) {
|
|
148
|
+
chatCompletion.push({
|
|
149
|
+
content: textContent,
|
|
150
|
+
order: order++,
|
|
151
|
+
});
|
|
152
|
+
textContent = '';
|
|
153
|
+
}
|
|
154
|
+
await this.saveToolUse(Array.from(tools.values()));
|
|
155
|
+
await this.saveChatSources(sources);
|
|
156
|
+
await this.saveChatTextContent(chatCompletion);
|
|
157
|
+
this.eventEmitter.emit('message.new', assistantMessage);
|
|
158
|
+
observer.complete();
|
|
159
|
+
})();
|
|
160
|
+
},
|
|
161
|
+
});
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
exports.SendChatUC = SendChatUC;
|
|
166
|
+
//# sourceMappingURL=SendChatUC.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SendChatUC.js","sourceRoot":"/","sources":["domain/use-cases/chats/SendChatUC.ts"],"names":[],"mappings":";;;;;;;;;;;;AAgBA,qDAMyB;AACzB,+BAAkC;AAElC,MAAa,gBAAgB;IAG3B,cAAc,CAAU;IAIxB,OAAO,CAAU;IAKjB,aAAa,CAAkB;IAK/B,WAAW,CAAY;IAKvB,KAAK,CAAU;CAChB;AAvBD,4CAuBC;AApBC;IAFC,IAAA,0BAAQ,GAAE;IACV,IAAA,4BAAU,GAAE;;wDACW;AAIxB;IAFC,IAAA,0BAAQ,GAAE;IACV,IAAA,4BAAU,GAAE;;iDACI;AAKjB;IAHC,IAAA,yBAAO,GAAE;IACT,IAAA,gCAAc,EAAC,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;IAC9B,IAAA,4BAAU,GAAE;;uDACkB;AAK/B;IAHC,IAAA,yBAAO,GAAE;IACT,IAAA,0BAAQ,EAAC,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;IACxB,IAAA,4BAAU,GAAE;;qDACU;AAKvB;IAHC,IAAA,0BAAQ,GAAE;IACV,IAAA,4BAAU,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AC;wBACzC,WAAW,IAAI,KAAK,CAAC,OAAO,CAAC;oBAC/B,CAAC;gBACH,CAAC;gBACD,QAAQ,EAAE,GAAG,EAAE;oBACb,KAAK,CAAC,KAAK,IAAI,EAAE;wBACf,IAAI,WAAW,EAAE,CAAC;4BAChB,cAAc,CAAC,IAAI,CAAC;gCAClB,OAAO,EAAE,WAAW;gCACpB,KAAK,EAAE,KAAK,EAAE;6BACf,CAAC,CAAC;4BACH,WAAW,GAAG,EAAE,CAAC;wBACnB,CAAC;wBACD,MAAM,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;wBACnD,MAAM,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC;wBACpC,MAAM,IAAI,CAAC,mBAAmB,CAAC,cAAc,CAAC,CAAC;wBAE/C,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,aAAa,EAAE,gBAAgB,CAAC,CAAC;wBAExD,QAAQ,CAAC,QAAQ,EAAE,CAAC;oBACtB,CAAC,CAAC,EAAE,CAAC;gBACP,CAAC;aACF,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;CASF;AArJD,gCAqJC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { UserEntity } from '@domain/entities/UserEntity';
|
|
2
|
+
import { DynamicStructuredTool } from 'langchain';
|
|
3
|
+
export type AvailableTool = {
|
|
4
|
+
name: string;
|
|
5
|
+
options: Record<string, unknown>;
|
|
6
|
+
};
|
|
7
|
+
export type ToolNames<AvailableTools extends AvailableTool[]> = AvailableTools[number]['name'];
|
|
8
|
+
export type StreamEvents<AvailableTools extends AvailableTool[]> = {
|
|
9
|
+
event: 'chat_stream';
|
|
10
|
+
content: string;
|
|
11
|
+
} | {
|
|
12
|
+
event: 'sources_add';
|
|
13
|
+
sources: Source[];
|
|
14
|
+
} | {
|
|
15
|
+
event: 'tool_stream_start';
|
|
16
|
+
name: ToolNames<AvailableTools>;
|
|
17
|
+
id: string;
|
|
18
|
+
} | {
|
|
19
|
+
event: 'tool_start';
|
|
20
|
+
name: ToolNames<AvailableTools>;
|
|
21
|
+
id: string;
|
|
22
|
+
input: unknown;
|
|
23
|
+
} | {
|
|
24
|
+
event: 'tool_stream';
|
|
25
|
+
id: string;
|
|
26
|
+
input: string;
|
|
27
|
+
} | {
|
|
28
|
+
event: 'tool_end';
|
|
29
|
+
name: ToolNames<AvailableTools>;
|
|
30
|
+
input: string;
|
|
31
|
+
output: unknown;
|
|
32
|
+
id: string;
|
|
33
|
+
};
|
|
34
|
+
export type ChatStreamEvents<AvailableTools extends AvailableTool[]> = StreamEvents<AvailableTools> | {
|
|
35
|
+
event: 'user_message_id';
|
|
36
|
+
id: string;
|
|
37
|
+
} | {
|
|
38
|
+
event: 'assistant_message_id';
|
|
39
|
+
id: string;
|
|
40
|
+
};
|
|
41
|
+
export type Source = {
|
|
42
|
+
title: string;
|
|
43
|
+
link: string;
|
|
44
|
+
content: string;
|
|
45
|
+
index: number;
|
|
46
|
+
};
|
|
47
|
+
export type ToolOptions = {
|
|
48
|
+
getSourceIndex: () => number;
|
|
49
|
+
addSources: (sources: Source[]) => void;
|
|
50
|
+
currentUser: UserEntity;
|
|
51
|
+
};
|
|
52
|
+
export interface ToolClass {
|
|
53
|
+
getTool(options: ToolOptions): DynamicStructuredTool;
|
|
54
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chat.types.js","sourceRoot":"/","sources":["domain/use-cases/chats/chat.types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ConversationEntity } from '@domain/entities/ConversationEntity';
|
|
2
|
+
import { UCInput } from '@domain/use-cases/_common';
|
|
3
|
+
export declare const CREATE_CONVERSATION_UC = "CreateConversationUC";
|
|
4
|
+
export interface ICreateConversationUC {
|
|
5
|
+
execute(input: UCInput<undefined>): Promise<ConversationEntity>;
|
|
6
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CreateConversationUC.js","sourceRoot":"/","sources":["domain/use-cases/conversations/CreateConversationUC.ts"],"names":[],"mappings":";;;AAGa,QAAA,sBAAsB,GAAG,sBAAsB,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { ConversationEntity } from '@domain/entities/ConversationEntity';
|
|
2
|
+
import type { ConversationRepository } from '@domain/interfaces/ConversationRepository';
|
|
3
|
+
import { DeleteByIdInput, UCInput } from '@domain/use-cases/_common';
|
|
4
|
+
import type { IGetConversationUC } from '@domain/use-cases/conversations/GetConversationUC';
|
|
5
|
+
export declare class DeleteConversationUC {
|
|
6
|
+
private readonly conversationRepository;
|
|
7
|
+
private readonly getConversationUC;
|
|
8
|
+
constructor(conversationRepository: ConversationRepository, getConversationUC: IGetConversationUC);
|
|
9
|
+
execute({ input, currentUser, }: UCInput<DeleteByIdInput>): Promise<ConversationEntity>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.DeleteConversationUC = void 0;
|
|
16
|
+
const ConversationRepository_1 = require("@domain/interfaces/ConversationRepository");
|
|
17
|
+
const GetConversationUC_1 = require("@domain/use-cases/conversations/GetConversationUC");
|
|
18
|
+
const common_1 = require("@nestjs/common");
|
|
19
|
+
let DeleteConversationUC = class DeleteConversationUC {
|
|
20
|
+
conversationRepository;
|
|
21
|
+
getConversationUC;
|
|
22
|
+
constructor(conversationRepository, getConversationUC) {
|
|
23
|
+
this.conversationRepository = conversationRepository;
|
|
24
|
+
this.getConversationUC = getConversationUC;
|
|
25
|
+
}
|
|
26
|
+
async execute({ input, currentUser, }) {
|
|
27
|
+
const conversation = await this.getConversationUC.execute({
|
|
28
|
+
input: { id: input.id },
|
|
29
|
+
currentUser,
|
|
30
|
+
});
|
|
31
|
+
return await this.conversationRepository.remove(conversation);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
exports.DeleteConversationUC = DeleteConversationUC;
|
|
35
|
+
exports.DeleteConversationUC = DeleteConversationUC = __decorate([
|
|
36
|
+
(0, common_1.Injectable)(),
|
|
37
|
+
__param(0, (0, common_1.Inject)(ConversationRepository_1.CONVERSATION_REPOSITORY)),
|
|
38
|
+
__param(1, (0, common_1.Inject)(GetConversationUC_1.GET_CONVERSATION_UC)),
|
|
39
|
+
__metadata("design:paramtypes", [Object, Object])
|
|
40
|
+
], DeleteConversationUC);
|
|
41
|
+
//# sourceMappingURL=DeleteConversationUC.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DeleteConversationUC.js","sourceRoot":"/","sources":["domain/use-cases/conversations/DeleteConversationUC.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAEA,sFAAoF;AAGpF,yFAAwF;AACxF,2CAAoD;AAG7C,IAAM,oBAAoB,GAA1B,MAAM,oBAAoB;IAGZ;IAEA;IAJnB,YAEmB,sBAA8C,EAE9C,iBAAqC;QAFrC,2BAAsB,GAAtB,sBAAsB,CAAwB;QAE9C,sBAAiB,GAAjB,iBAAiB,CAAoB;IACrD,CAAC;IAEJ,KAAK,CAAC,OAAO,CAAC,EACZ,KAAK,EACL,WAAW,GACc;QACzB,MAAM,YAAY,GAAG,MAAM,IAAI,CAAC,iBAAiB,CAAC,OAAO,CAAC;YACxD,KAAK,EAAE,EAAE,EAAE,EAAE,KAAK,CAAC,EAAE,EAAE;YACvB,WAAW;SACZ,CAAC,CAAC;QAEH,OAAO,MAAM,IAAI,CAAC,sBAAsB,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;IAChE,CAAC;CACF,CAAA;AAnBY,oDAAoB;+BAApB,oBAAoB;IADhC,IAAA,mBAAU,GAAE;IAGR,WAAA,IAAA,eAAM,EAAC,gDAAuB,CAAC,CAAA;IAE/B,WAAA,IAAA,eAAM,EAAC,uCAAmB,CAAC,CAAA;;GAJnB,oBAAoB,CAmBhC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { ConversationEntity } from '@domain/entities/ConversationEntity';
|
|
2
|
+
import type { ConversationRepository } from '@domain/interfaces/ConversationRepository';
|
|
3
|
+
import type { LLMService } from '@domain/interfaces/LLMService';
|
|
4
|
+
import type { PromptService } from '@domain/interfaces/PromptService';
|
|
5
|
+
import { UCInput } from '@domain/use-cases/_common';
|
|
6
|
+
import type { IGetConversationUC } from '@domain/use-cases/conversations/GetConversationUC';
|
|
7
|
+
export declare class GenerateConversationTitleInput {
|
|
8
|
+
conversationId: string;
|
|
9
|
+
firstMessage: string;
|
|
10
|
+
}
|
|
11
|
+
export declare class GenerateConversationTitleUC {
|
|
12
|
+
private readonly llmService;
|
|
13
|
+
private readonly promptService;
|
|
14
|
+
private readonly getConversationUC;
|
|
15
|
+
private readonly conversationRepository;
|
|
16
|
+
constructor(llmService: LLMService, promptService: PromptService, getConversationUC: IGetConversationUC, conversationRepository: ConversationRepository);
|
|
17
|
+
execute({ input, currentUser, }: UCInput<GenerateConversationTitleInput>): Promise<ConversationEntity>;
|
|
18
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.GenerateConversationTitleUC = exports.GenerateConversationTitleInput = void 0;
|
|
16
|
+
const ConversationRepository_1 = require("@domain/interfaces/ConversationRepository");
|
|
17
|
+
const LLMService_1 = require("@domain/interfaces/LLMService");
|
|
18
|
+
const PromptService_1 = require("@domain/interfaces/PromptService");
|
|
19
|
+
const GetConversationUC_1 = require("@domain/use-cases/conversations/GetConversationUC");
|
|
20
|
+
const common_1 = require("@nestjs/common");
|
|
21
|
+
const graphql_1 = require("@nestjs/graphql");
|
|
22
|
+
let GenerateConversationTitleInput = class GenerateConversationTitleInput {
|
|
23
|
+
conversationId;
|
|
24
|
+
firstMessage;
|
|
25
|
+
};
|
|
26
|
+
exports.GenerateConversationTitleInput = GenerateConversationTitleInput;
|
|
27
|
+
__decorate([
|
|
28
|
+
(0, graphql_1.Field)(() => graphql_1.ID),
|
|
29
|
+
__metadata("design:type", String)
|
|
30
|
+
], GenerateConversationTitleInput.prototype, "conversationId", void 0);
|
|
31
|
+
__decorate([
|
|
32
|
+
(0, graphql_1.Field)(() => String),
|
|
33
|
+
__metadata("design:type", String)
|
|
34
|
+
], GenerateConversationTitleInput.prototype, "firstMessage", void 0);
|
|
35
|
+
exports.GenerateConversationTitleInput = GenerateConversationTitleInput = __decorate([
|
|
36
|
+
(0, graphql_1.InputType)()
|
|
37
|
+
], GenerateConversationTitleInput);
|
|
38
|
+
let GenerateConversationTitleUC = class GenerateConversationTitleUC {
|
|
39
|
+
llmService;
|
|
40
|
+
promptService;
|
|
41
|
+
getConversationUC;
|
|
42
|
+
conversationRepository;
|
|
43
|
+
constructor(llmService, promptService, getConversationUC, conversationRepository) {
|
|
44
|
+
this.llmService = llmService;
|
|
45
|
+
this.promptService = promptService;
|
|
46
|
+
this.getConversationUC = getConversationUC;
|
|
47
|
+
this.conversationRepository = conversationRepository;
|
|
48
|
+
}
|
|
49
|
+
async execute({ input, currentUser, }) {
|
|
50
|
+
const conversation = await this.getConversationUC.execute({
|
|
51
|
+
currentUser,
|
|
52
|
+
input: { id: input.conversationId },
|
|
53
|
+
});
|
|
54
|
+
const model = this.llmService.getLLM({
|
|
55
|
+
model: 'gpt-5-nano', // TODO: make this configurable
|
|
56
|
+
provider: 'openai',
|
|
57
|
+
temperature: 0.1,
|
|
58
|
+
streaming: false,
|
|
59
|
+
});
|
|
60
|
+
const result = await model.invoke(await this.promptService.getPrompt({
|
|
61
|
+
name: 'generate_conversation_title',
|
|
62
|
+
version: 'latest',
|
|
63
|
+
}, {
|
|
64
|
+
first_message: input.firstMessage,
|
|
65
|
+
}));
|
|
66
|
+
conversation.title = result.text;
|
|
67
|
+
await this.conversationRepository.save(conversation);
|
|
68
|
+
return conversation;
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
exports.GenerateConversationTitleUC = GenerateConversationTitleUC;
|
|
72
|
+
exports.GenerateConversationTitleUC = GenerateConversationTitleUC = __decorate([
|
|
73
|
+
(0, common_1.Injectable)(),
|
|
74
|
+
__param(0, (0, common_1.Inject)(LLMService_1.LLM_SERVICE)),
|
|
75
|
+
__param(1, (0, common_1.Inject)(PromptService_1.PROMPT_SERVICE)),
|
|
76
|
+
__param(2, (0, common_1.Inject)(GetConversationUC_1.GET_CONVERSATION_UC)),
|
|
77
|
+
__param(3, (0, common_1.Inject)(ConversationRepository_1.CONVERSATION_REPOSITORY)),
|
|
78
|
+
__metadata("design:paramtypes", [Object, Object, Object, Object])
|
|
79
|
+
], GenerateConversationTitleUC);
|
|
80
|
+
//# sourceMappingURL=GenerateConversationTitleUC.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GenerateConversationTitleUC.js","sourceRoot":"/","sources":["domain/use-cases/conversations/GenerateConversationTitleUC.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAEA,sFAAoF;AAEpF,8DAA4D;AAE5D,oEAAkE;AAGlE,yFAAwF;AACxF,2CAAoD;AACpD,6CAAuD;AAGhD,IAAM,8BAA8B,GAApC,MAAM,8BAA8B;IAEzC,cAAc,CAAU;IAGxB,YAAY,CAAU;CACvB,CAAA;AANY,wEAA8B;AAEzC;IADC,IAAA,eAAK,EAAC,GAAG,EAAE,CAAC,YAAE,CAAC;;sEACQ;AAGxB;IADC,IAAA,eAAK,EAAC,GAAG,EAAE,CAAC,MAAM,CAAC;;oEACE;yCALX,8BAA8B;IAD1C,IAAA,mBAAS,GAAE;GACC,8BAA8B,CAM1C;AAGM,IAAM,2BAA2B,GAAjC,MAAM,2BAA2B;IAGnB;IAEA;IAEA;IAEA;IARnB,YAEmB,UAAsB,EAEtB,aAA4B,EAE5B,iBAAqC,EAErC,sBAA8C;QAN9C,eAAU,GAAV,UAAU,CAAY;QAEtB,kBAAa,GAAb,aAAa,CAAe;QAE5B,sBAAiB,GAAjB,iBAAiB,CAAoB;Q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use-cases/_common';
|
|
3
|
+
export declare class GetConversationInput {
|
|
4
|
+
id?: string;
|
|
5
|
+
shareId?: string;
|
|
6
|
+
}
|
|
7
|
+
export declare const GET_CONVERSATION_UC = "GetConversationUC";
|
|
8
|
+
export interface IGetConversationUC {
|
|
9
|
+
execute(input: UCInput<GetConversationInput>): Promise<ConversationEntity>;
|
|
10
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.GET_CONVERSATION_UC = exports.GetConversationInput = void 0;
|
|
13
|
+
const graphql_1 = require("@nestjs/graphql");
|
|
14
|
+
let GetConversationInput = class GetConversationInput {
|
|
15
|
+
id;
|
|
16
|
+
shareId;
|
|
17
|
+
};
|
|
18
|
+
exports.GetConversationInput = GetConversationInput;
|
|
19
|
+
__decorate([
|
|
20
|
+
(0, graphql_1.Field)(() => graphql_1.ID, { nullable: true }),
|
|
21
|
+
__metadata("design:type", String)
|
|
22
|
+
], GetConversationInput.prototype, "id", void 0);
|
|
23
|
+
__decorate([
|
|
24
|
+
(0, graphql_1.Field)(() => String, { nullable: true }),
|
|
25
|
+
__metadata("design:type", String)
|
|
26
|
+
], GetConversationInput.prototype, "shareId", void 0);
|
|
27
|
+
exports.GetConversationInput = GetConversationInput = __decorate([
|
|
28
|
+
(0, graphql_1.InputType)()
|
|
29
|
+
], GetConversationInput);
|
|
30
|
+
exports.GET_CONVERSATION_UC = 'GetConversationUC';
|
|
31
|
+
//# sourceMappingURL=GetConversationUC.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GetConversationUC.js","sourceRoot":"/","sources":["domain/use-cases/conversations/GetConversationUC.ts"],"names":[],"mappings":";;;;;;;;;;;;AAEA,6CAAuD;AAGhD,IAAM,oBAAoB,GAA1B,MAAM,oBAAoB;IAE/B,EAAE,CAAU;IAGZ,OAAO,CAAU;CAClB,CAAA;AANY,oDAAoB;AAE/B;IADC,IAAA,eAAK,EAAC,GAAG,EAAE,CAAC,YAAE,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;;gDACxB;AAGZ;IADC,IAAA,eAAK,EAAC,GAAG,EAAE,CAAC,MAAM,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;;qDACvB;+BALN,oBAAoB;IADhC,IAAA,mBAAS,GAAE;GACC,oBAAoB,CAMhC;AAEY,QAAA,mBAAmB,GAAG,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ConversationEntity } from '@domain/entities/ConversationEntity';
|
|
2
|
+
import { PaginatedInput, PaginatedOutput, UCInput } from '@domain/use-cases/_common';
|
|
3
|
+
export declare class GetConversationsInput extends PaginatedInput {
|
|
4
|
+
title?: string;
|
|
5
|
+
}
|
|
6
|
+
export declare const GET_CONVERSATIONS_UC = "GetConversationsUC";
|
|
7
|
+
export interface IGetConversationsUC {
|
|
8
|
+
execute(input: UCInput<GetConversationsInput>): Promise<PaginatedOutput<ConversationEntity>>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.GET_CONVERSATIONS_UC = exports.GetConversationsInput = void 0;
|
|
13
|
+
const _common_1 = require("@domain/use-cases/_common");
|
|
14
|
+
const graphql_1 = require("@nestjs/graphql");
|
|
15
|
+
let GetConversationsInput = class GetConversationsInput extends _common_1.PaginatedInput {
|
|
16
|
+
title;
|
|
17
|
+
};
|
|
18
|
+
exports.GetConversationsInput = GetConversationsInput;
|
|
19
|
+
__decorate([
|
|
20
|
+
(0, graphql_1.Field)(() => String, { nullable: true }),
|
|
21
|
+
__metadata("design:type", String)
|
|
22
|
+
], GetConversationsInput.prototype, "title", void 0);
|
|
23
|
+
exports.GetConversationsInput = GetConversationsInput = __decorate([
|
|
24
|
+
(0, graphql_1.InputType)()
|
|
25
|
+
], GetConversationsInput);
|
|
26
|
+
exports.GET_CONVERSATIONS_UC = 'GetConversationsUC';
|
|
27
|
+
//# sourceMappingURL=GetConversationsUC.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GetConversationsUC.js","sourceRoot":"/","sources":["domain/use-cases/conversations/GetConversationsUC.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,uDAImC;AACnC,6CAAmD;AAG5C,IAAM,qBAAqB,GAA3B,MAAM,qBAAsB,SAAQ,wBAAc;IAEvD,KAAK,CAAU;CAChB,CAAA;AAHY,sDAAqB;AAEhC;IADC,IAAA,eAAK,EAAC,GAAG,EAAE,CAAC,MAAM,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;;oDACzB;gCAFJ,qBAAqB;IADjC,IAAA,mBAAS,GAAE;GACC,qBAAqB,CAGjC;AAEY,QAAA,oBAAoB,GAAG,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ConversationEntity } from '@domain/entities/ConversationEntity';
|
|
2
|
+
import type { ConversationRepository } from '@domain/interfaces/ConversationRepository';
|
|
3
|
+
import { UCInput } from '@domain/use-cases/_common';
|
|
4
|
+
import type { IGetConversationUC } from '@domain/use-cases/conversations/GetConversationUC';
|
|
5
|
+
export declare class UpdateConversationInput {
|
|
6
|
+
id: string;
|
|
7
|
+
title?: string;
|
|
8
|
+
shared?: boolean;
|
|
9
|
+
}
|
|
10
|
+
export declare class UpdateConversationUC {
|
|
11
|
+
private readonly conversationRepository;
|
|
12
|
+
private readonly getConversationUC;
|
|
13
|
+
constructor(conversationRepository: ConversationRepository, getConversationUC: IGetConversationUC);
|
|
14
|
+
execute({ input, currentUser, }: UCInput<UpdateConversationInput>): Promise<ConversationEntity>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.UpdateConversationUC = exports.UpdateConversationInput = void 0;
|
|
16
|
+
const ConversationRepository_1 = require("@domain/interfaces/ConversationRepository");
|
|
17
|
+
const GetConversationUC_1 = require("@domain/use-cases/conversations/GetConversationUC");
|
|
18
|
+
const common_1 = require("@nestjs/common");
|
|
19
|
+
const graphql_1 = require("@nestjs/graphql");
|
|
20
|
+
let UpdateConversationInput = class UpdateConversationInput {
|
|
21
|
+
id;
|
|
22
|
+
title;
|
|
23
|
+
shared;
|
|
24
|
+
};
|
|
25
|
+
exports.UpdateConversationInput = UpdateConversationInput;
|
|
26
|
+
__decorate([
|
|
27
|
+
(0, graphql_1.Field)(() => graphql_1.ID),
|
|
28
|
+
__metadata("design:type", String)
|
|
29
|
+
], UpdateConversationInput.prototype, "id", void 0);
|
|
30
|
+
__decorate([
|
|
31
|
+
(0, graphql_1.Field)({ nullable: true }),
|
|
32
|
+
__metadata("design:type", String)
|
|
33
|
+
], UpdateConversationInput.prototype, "title", void 0);
|
|
34
|
+
__decorate([
|
|
35
|
+
(0, graphql_1.Field)({ nullable: true }),
|
|
36
|
+
__metadata("design:type", Boolean)
|
|
37
|
+
], UpdateConversationInput.prototype, "shared", void 0);
|
|
38
|
+
exports.UpdateConversationInput = UpdateConversationInput = __decorate([
|
|
39
|
+
(0, graphql_1.InputType)()
|
|
40
|
+
], UpdateConversationInput);
|
|
41
|
+
let UpdateConversationUC = class UpdateConversationUC {
|
|
42
|
+
conversationRepository;
|
|
43
|
+
getConversationUC;
|
|
44
|
+
constructor(conversationRepository, getConversationUC) {
|
|
45
|
+
this.conversationRepository = conversationRepository;
|
|
46
|
+
this.getConversationUC = getConversationUC;
|
|
47
|
+
}
|
|
48
|
+
async execute({ input, currentUser, }) {
|
|
49
|
+
const conversation = await this.getConversationUC.execute({
|
|
50
|
+
input: { id: input.id },
|
|
51
|
+
currentUser,
|
|
52
|
+
});
|
|
53
|
+
if (typeof input.title === 'string') {
|
|
54
|
+
conversation.title = input.title;
|
|
55
|
+
}
|
|
56
|
+
if (typeof input.shared === 'boolean') {
|
|
57
|
+
if (input.shared) {
|
|
58
|
+
conversation.shareId = crypto.randomUUID();
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
conversation.shareId = null;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return this.conversationRepository.save(conversation);
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
exports.UpdateConversationUC = UpdateConversationUC;
|
|
68
|
+
exports.UpdateConversationUC = UpdateConversationUC = __decorate([
|
|
69
|
+
(0, common_1.Injectable)(),
|
|
70
|
+
__param(0, (0, common_1.Inject)(ConversationRepository_1.CONVERSATION_REPOSITORY)),
|
|
71
|
+
__param(1, (0, common_1.Inject)(GetConversationUC_1.GET_CONVERSATION_UC)),
|
|
72
|
+
__metadata("design:paramtypes", [Object, Object])
|
|
73
|
+
], UpdateConversationUC);
|
|
74
|
+
//# sourceMappingURL=UpdateConversationUC.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"UpdateConversationUC.js","sourceRoot":"/","sources":["domain/use-cases/conversations/UpdateConversationUC.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAEA,sFAAoF;AAGpF,yFAAwF;AACxF,2CAAoD;AACpD,6CAAuD;AAGhD,IAAM,uBAAuB,GAA7B,MAAM,uBAAuB;IAElC,EAAE,CAAU;IAGZ,KAAK,CAAU;IAGf,MAAM,CAAW;CAClB,CAAA;AATY,0DAAuB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AAC,gDAAuB,CAAC,CAAA;IAE/B,WAAA,IAAA,eAAM,EAAC,uCAAmB,CAAC,CAAA;;GAJnB,oBAAoB,CA+BhC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './chatbot-api.module';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./chatbot-api.module"), exports);
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"/","sources":["index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,uDAAqC"}
|