|
|
@@ -33,6 +33,7 @@ import {
|
|
|
type AccessibleAiAssistants, type AiAssistant, AiAssistantAccessScope, AiAssistantShareScope,
|
|
|
} from '../../interfaces/ai-assistant';
|
|
|
import type { MessageListParams } from '../../interfaces/message';
|
|
|
+import { ThreadType } from '../../interfaces/thread-relation';
|
|
|
import { removeGlobPath } from '../../utils/remove-glob-path';
|
|
|
import AiAssistantModel, { type AiAssistantDocument } from '../models/ai-assistant';
|
|
|
import { convertMarkdownToHtml } from '../utils/convert-markdown-to-html';
|
|
|
@@ -65,7 +66,7 @@ const convertPathPatternsToRegExp = (pagePathPatterns: string[]): Array<string |
|
|
|
};
|
|
|
|
|
|
export interface IOpenaiService {
|
|
|
- createThread(userId: string, isEditorAssistant: boolean, aiAssistantId?: string, initialUserMessage?: string): Promise<ThreadRelationDocument>;
|
|
|
+ createThread(userId: string, threadType: ThreadType, aiAssistantId?: string, initialUserMessage?: string): Promise<ThreadRelationDocument>;
|
|
|
getThreadsByAiAssistantId(aiAssistantId: string): Promise<ThreadRelationDocument[]>
|
|
|
deleteThread(threadRelationId: string): Promise<ThreadRelationDocument>;
|
|
|
deleteExpiredThreads(limit: number, apiCallInterval: number): Promise<void>; // for CronJob
|
|
|
@@ -117,7 +118,7 @@ class OpenaiService implements IOpenaiService {
|
|
|
return threadTitle;
|
|
|
}
|
|
|
|
|
|
- async createThread(userId: string, isEditorAssistant: boolean, aiAssistantId?: string, initialUserMessage?: string): Promise<ThreadRelationDocument> {
|
|
|
+ async createThread(userId: string, threadType: ThreadType, aiAssistantId?: string, initialUserMessage?: string): Promise<ThreadRelationDocument> {
|
|
|
let threadTitle: string | null = null;
|
|
|
if (initialUserMessage != null) {
|
|
|
try {
|
|
|
@@ -133,7 +134,7 @@ class OpenaiService implements IOpenaiService {
|
|
|
const thread = await this.client.createThread(vectorStoreRelation?.vectorStoreId);
|
|
|
const threadRelation = await ThreadRelationModel.create({
|
|
|
userId,
|
|
|
- isEditorAssistant,
|
|
|
+ threadType,
|
|
|
aiAssistant: aiAssistantId,
|
|
|
threadId: thread.id,
|
|
|
title: threadTitle,
|
|
|
@@ -158,8 +159,8 @@ class OpenaiService implements IOpenaiService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- async getThreadsByAiAssistantId(aiAssistantId: string): Promise<ThreadRelationDocument[]> {
|
|
|
- const threadRelations = await ThreadRelationModel.find({ aiAssistant: aiAssistantId, isEditorAssistant: false });
|
|
|
+ async getThreadsByAiAssistantId(aiAssistantId: string, threadType: ThreadType = ThreadType.KNOWLEDGE): Promise<ThreadRelationDocument[]> {
|
|
|
+ const threadRelations = await ThreadRelationModel.find({ aiAssistant: aiAssistantId, threadType });
|
|
|
return threadRelations;
|
|
|
}
|
|
|
|