Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion backend/.development.env
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ AMPLITUDE_API_KEY=
PRIVATE_KEY=MySuperSecretEncryptionPrivateKey

# do not forget change the key from test to prodaction version, if you need stripe
STRIPE_SECRET_KEY=sk_test_51JM8FBFtHdda1TsB9lt1dIvbA9hcrqkTVqgvUqGw6tgBpBRvNrBdSrR8qh8GfNc5rkQr5TfSHHAsxxZwDWyByovO00BikGnMAZ
STRIPE_SECRET_KEY=sk_test_51JM8FBFtHdda...ovO00BikGnMAZ

# adress external web socket server for management agent connection
WS_SERVER_URL=http://ws-server
Expand All @@ -54,8 +54,11 @@ ANNUAL_ENTERPRISE_PLAN_PRICE_ID=
STRIPE_ENDPOINT_SECRET=

JWT_SECRET=MySuperSecretJwtSecret

TEMPORARY_JWT_SECRET=MySuperSecretTemporaryJwtSecret

SESSION_SECRET=MySuperSecretSessionSecret

# for authorization with google
GOOGLE_CLIENT_ID=

Expand Down
4 changes: 3 additions & 1 deletion backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"@sentry/minimal": "^6.19.7",
"@sentry/node": "8.52.0",
"@types/crypto-js": "^4.2.2",
"@types/express-session": "^1.18.2",
"@types/jsonwebtoken": "^9.0.10",
"@types/multer": "^2.0.0",
"@types/nodemailer": "^6.4.17",
Expand All @@ -70,6 +71,7 @@
"eslint-plugin-security": "3.0.1",
"express": "5.1.0",
"express-rate-limit": "7.5.1",
"express-session": "^1.18.1",
"fetch-blob": "^4.0.0",
"helmet": "8.1.0",
"ip-range-check": "0.2.0",
Expand All @@ -81,7 +83,7 @@
"node-gyp": "^11.2.0",
"nodemailer": "^7.0.4",
"nunjucks": "^3.2.4",
"openai": "^4.100.0",
"openai": "^5.8.2",
"otplib": "^12.0.1",
"p-queue": "8.1.0",
"pg-connection-string": "^2.9.1",
Expand Down
1 change: 1 addition & 0 deletions backend/src/common/data-injection.tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ export enum UseCaseType {
DELETE_API_KEY = 'DELETE_API_KEY',

REQUEST_INFO_FROM_TABLE_WITH_AI = 'REQUEST_INFO_FROM_TABLE_WITH_AI',
REQUEST_INFO_FROM_TABLE_WITH_AI_V2 = 'REQUEST_INFO_FROM_TABLE_WITH_AI_V2',

CREATE_THREAD_WITH_AI_ASSISTANT = 'CREATE_THREAD_WITH_AI_ASSISTANT',
ADD_MESSAGE_TO_THREAD_WITH_AI_ASSISTANT = 'ADD_MESSAGE_TO_THREAD_WITH_AI_ASSISTANT',
Expand Down
9 changes: 8 additions & 1 deletion backend/src/entities/ai/ai-use-cases.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import { AddMessageToThreadWithAssistantDS } from './application/data-structures
import { CreateThreadWithAssistantDS } from './application/data-structures/create-thread-with-assistant.ds.js';
import { DeleteThreadWithAssistantDS } from './application/data-structures/delete-thread-with-assistant.ds.js';
import { FindAllThreadMessagesDS } from './application/data-structures/find-all-thread-messages.ds.js';
import { RequestInfoFromTableDS } from './application/data-structures/request-info-from-table.ds.js';
import {
RequestInfoFromTableDS,
RequestInfoFromTableDSV2,
} from './application/data-structures/request-info-from-table.ds.js';
import { ResponseInfoDS } from './application/data-structures/response-info.ds.js';
import { FoundUserThreadMessagesRO } from './application/dto/found-user-thread-messages.ro.js';
import { FoundUserThreadsWithAiRO } from './application/dto/found-user-threads-with-ai.ro.js';
Expand All @@ -13,6 +16,10 @@ export interface IRequestInfoFromTable {
execute(inputData: RequestInfoFromTableDS, inTransaction: InTransactionEnum): Promise<ResponseInfoDS>;
}

export interface IRequestInfoFromTableV2 {
execute(inputData: RequestInfoFromTableDSV2, inTransaction: InTransactionEnum): Promise<void>;
}

export interface ICreateThreadWithAIAssistant {
execute(inputData: CreateThreadWithAssistantDS, inTransaction: InTransactionEnum): Promise<void>;
}
Expand Down
29 changes: 18 additions & 11 deletions backend/src/entities/ai/ai.module.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
import { MiddlewareConsumer, Module, NestModule, RequestMethod } from '@nestjs/common';
import { UserAIRequestsController } from './user-ai-requests.controller.js';
import { BaseType, UseCaseType } from '../../common/data-injection.tokens.js';
import { GlobalDatabaseContext } from '../../common/application/global-database-context.js';
import { RequestInfoFromTableWithAIUseCase } from './use-cases/request-info-from-table-with-ai.use.case.js';
import { AuthMiddleware } from '../../authorization/auth.middleware.js';
import { TypeOrmModule } from '@nestjs/typeorm';
import { UserEntity } from '../user/user.entity.js';
import { AuthMiddleware } from '../../authorization/auth.middleware.js';
import { GlobalDatabaseContext } from '../../common/application/global-database-context.js';
import { BaseType, UseCaseType } from '../../common/data-injection.tokens.js';
import { LogOutEntity } from '../log-out/log-out.entity.js';
import { UserAIThreadsController } from './user-ai-threads.controller.js';
import { CreateThreadWithAIAssistantUseCase } from './use-cases/create-thread-with-ai-assistant.use.case.js';
import { UserEntity } from '../user/user.entity.js';
import { AddMessageToThreadWithAIAssistantUseCase } from './use-cases/add-message-to-thread-with-ai.use.case.js';
import { FindAllUserThreadsWithAssistantUseCase } from './use-cases/find-all-user-threads-with-assistant.use.case.js';
import { FindAllMessagesInAiThreadUseCase } from './use-cases/find-all-messages-in-ai-thread.use.case.js';
import { CreateThreadWithAIAssistantUseCase } from './use-cases/create-thread-with-ai-assistant.use.case.js';
import { DeleteThreadWithAIAssistantUseCase } from './use-cases/delete-thread-with-ai-assistant.use.case.js';
import { FindAllMessagesInAiThreadUseCase } from './use-cases/find-all-messages-in-ai-thread.use.case.js';
import { FindAllUserThreadsWithAssistantUseCase } from './use-cases/find-all-user-threads-with-assistant.use.case.js';
import { RequestInfoFromTableWithAIUseCaseV3 } from './use-cases/request-info-from-table-with-ai-v3.use.case.js';
import { RequestInfoFromTableWithAIUseCase } from './use-cases/request-info-from-table-with-ai.use.case.js';
import { UserAIRequestsControllerV2 } from './user-ai-requests-v2.controller.js';
import { UserAIRequestsController } from './user-ai-requests.controller.js';
import { UserAIThreadsController } from './user-ai-threads.controller.js';

@Module({
imports: [TypeOrmModule.forFeature([UserEntity, LogOutEntity])],
Expand All @@ -25,6 +27,10 @@ import { DeleteThreadWithAIAssistantUseCase } from './use-cases/delete-thread-wi
provide: UseCaseType.REQUEST_INFO_FROM_TABLE_WITH_AI,
useClass: RequestInfoFromTableWithAIUseCase,
},
{
provide: UseCaseType.REQUEST_INFO_FROM_TABLE_WITH_AI_V2,
useClass: RequestInfoFromTableWithAIUseCaseV3,
},
{
provide: UseCaseType.CREATE_THREAD_WITH_AI_ASSISTANT,
useClass: CreateThreadWithAIAssistantUseCase,
Expand All @@ -46,14 +52,15 @@ import { DeleteThreadWithAIAssistantUseCase } from './use-cases/delete-thread-wi
useClass: DeleteThreadWithAIAssistantUseCase,
},
],
controllers: [UserAIRequestsController, UserAIThreadsController],
controllers: [UserAIRequestsController, UserAIThreadsController, UserAIRequestsControllerV2],
})
export class AIModule implements NestModule {
public configure(consumer: MiddlewareConsumer): any {
consumer
.apply(AuthMiddleware)
.forRoutes(
{ path: '/ai/request/:connectionId', method: RequestMethod.POST },
{ path: '/ai/v2/request/:connectionId', method: RequestMethod.POST },
{ path: '/ai/thread/:connectionId', method: RequestMethod.POST },
{ path: '/ai/thread/message/:connectionId/:threadId', method: RequestMethod.POST },
{ path: '/ai/threads', method: RequestMethod.GET },
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import { Response } from 'express';
export class RequestInfoFromTableDS {
connectionId: string;
tableName: string;
user_message: string;
user_id: string;
master_password: string;
}
}

export class RequestInfoFromTableDSV2 extends RequestInfoFromTableDS {
response: Response;
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { getDataAccessObject } from '@rocketadmin/shared-code/dist/src/data-acce
import { TableStructureDS } from '@rocketadmin/shared-code/dist/src/data-access-layer/shared/data-structures/table-structure.ds.js';
import { getOpenAiClient } from '../utils/get-open-ai-client.js';
import { Readable } from 'stream';
import { FileLike } from 'openai/uploads.js';
import { Uploadable } from 'openai/uploads.js';
import { Blob } from 'fetch-blob';
import { File } from 'fetch-blob/file.js';
import { buildUserAiThreadEntity } from '../utils/build-ai-user-thread-entity.util.js';
Expand Down Expand Up @@ -102,7 +102,7 @@ export class CreateThreadWithAIAssistantUseCase

const blob = new Blob([allTablesStructuresData], { type: 'application/jsonl' });

const fileLike: FileLike = new File([blob], 'data.json', {
const fileLike: Uploadable = new File([blob], 'data.json', {
lastModified: Date.now(),
type: 'application/jsonl',
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class DeleteThreadWithAIAssistantUseCase

const { openai } = getOpenAiClient();

await openai.beta.threads.del(foundThread.thread_ai_id);
await openai.beta.threads.delete(foundThread.thread_ai_id);
await this._dbContext.aiUserThreadsRepository.delete(foundThread.id);

return {
Expand Down
Loading