Skip to content

Commit c385c58

Browse files
committed
feat(ai): introduce deep reading functionality and refactor AI module
- Added `AiDeepReadingController`, `AiDeepReadingService`, and related DTOs and models to support deep reading capabilities using AI. - Integrated new methods for generating and managing deep readings, including error handling and caching mechanisms. - Updated `AiModule` to include dependencies for deep reading services and controllers. - Removed the obsolete `AiAgentModule` and its associated test controller. - Enhanced configuration options to enable or disable deep reading features. Signed-off-by: Innei <[email protected]>
1 parent 17f3feb commit c385c58

37 files changed

+553
-58
lines changed

apps/core/global.d.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
import type { Document, PaginateModel } from 'mongoose'
2-
3-
import '@mx-space/compiled/zx-global'
4-
51
import type { ModelType } from '@typegoose/typegoose/lib/types'
2+
import type { Document, PaginateModel } from 'mongoose'
63

74
declare global {
85
export type KV<T = any> = Record<string, T>

apps/core/src/app.config.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import type { AxiosRequestConfig } from 'axios'
22

3+
import { argv } from '@mx-space/compiled'
4+
35
export const PORT = process.env.PORT || 2333
46
export const API_VERSION = 2
57

apps/core/src/bootstrap.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import type { LogLevel } from '@nestjs/common'
66
import type { NestFastifyApplication } from '@nestjs/platform-fastify'
77

88
import { Logger } from '@innei/pretty-logger-nestjs'
9+
import { chalk } from '@mx-space/compiled'
910
import { NestFactory } from '@nestjs/core'
1011

1112
import { CROSS_DOMAIN, DEBUG_MODE, PORT } from './app.config'

apps/core/src/common/exceptions/biz.exception.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ import { ErrorCode, ErrorCodeEnum } from '~/constants/error-code.constant'
44

55
export class BusinessException extends HttpException {
66
public bizCode: ErrorCodeEnum
7-
constructor(code: ErrorCodeEnum, extraMessage?: string)
7+
constructor(code: ErrorCodeEnum, extraMessage?: string, trace?: string)
88
constructor(message: string)
99
constructor(...args: any[]) {
1010
let status = 500
11-
const [bizCode, extraMessage] = args as any
11+
const [bizCode, extraMessage, trace] = args as any
1212
const bizError = ErrorCode[bizCode] || []
1313
const [message] = bizError
1414
status = bizError[1] ?? status
@@ -27,6 +27,8 @@ export class BusinessException extends HttpException {
2727
status,
2828
)
2929

30+
this.stack = trace
31+
3032
this.bizCode = typeof bizCode === 'number' ? bizCode : ErrorCodeEnum.Default
3133
}
3234
}

apps/core/src/common/filters/any-exception.filter.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1+
import { createWriteStream } from 'node:fs'
12
import { resolve } from 'node:path'
23
import type { ArgumentsHost, ExceptionFilter } from '@nestjs/common'
34
import type { FastifyReply, FastifyRequest } from 'fastify'
45
import type { WriteStream } from 'node:fs'
56

7+
import { chalk } from '@mx-space/compiled'
68
import {
79
Catch,
810
HttpException,
@@ -122,7 +124,7 @@ export class AllExceptionsFilter implements ExceptionFilter {
122124
if (!isDev) {
123125
this.errorLogPipe =
124126
this.errorLogPipe ??
125-
fs.createWriteStream(resolve(LOG_DIR, 'error.log'), {
127+
createWriteStream(resolve(LOG_DIR, 'error.log'), {
126128
flags: 'a+',
127129
encoding: 'utf-8',
128130
})

apps/core/src/common/interceptors/logging.interceptor.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import type {
1313
} from '@nestjs/common'
1414
import type { Observable } from 'rxjs'
1515

16+
import { chalk } from '@mx-space/compiled'
1617
import { Injectable, Logger, SetMetadata } from '@nestjs/common'
1718

1819
import { HTTP_REQUEST_TIME } from '~/constants/meta.constant'

apps/core/src/constants/db.constant.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export const RECENTLY_COLLECTION_NAME = 'recentlies'
1616
export const ANALYZE_COLLECTION_NAME = 'analyzes'
1717
export const WEBHOOK_EVENT_COLLECTION_NAME = 'webhook_events'
1818
export const AI_SUMMARY_COLLECTION_NAME = 'ai_summaries'
19+
export const AI_DEEP_READING_COLLECTION_NAME = 'ai_deep_readings'
1920

2021
export const USER_COLLECTION_NAME = 'users'
2122
export enum CollectionRefTypes {

apps/core/src/global/index.global.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import cluster from 'node:cluster'
2-
import { mkdirSync, writeFileSync } from 'node:fs'
2+
import { existsSync, mkdirSync, writeFileSync } from 'node:fs'
33

44
import { Logger } from '@nestjs/common'
55

@@ -18,7 +18,8 @@ import { cwd, isDev } from './env.global'
1818
import { registerJSONGlobal } from './json.global'
1919

2020
import './dayjs.global'
21-
import '@mx-space/compiled/zx-global'
21+
22+
import { $, chalk } from '@mx-space/compiled'
2223

2324
// 建立目录
2425
function createAppFolders() {
@@ -37,7 +38,7 @@ function createAppFolders() {
3738
Logger.log(chalk.blue(`文件回收站目录已经建好:${STATIC_FILE_TRASH_DIR}`))
3839

3940
const packageJSON = `${DATA_DIR}/package.json`
40-
const hasPKG = fs.existsSync(packageJSON)
41+
const hasPKG = existsSync(packageJSON)
4142
if (!hasPKG) {
4243
writeFileSync(packageJSON, '{"name":"modules"}', {
4344
flag: 'a',

apps/core/src/main.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
#!env node
22
// register global
33
import cluster from 'node:cluster'
4+
import { cpus } from 'node:os'
5+
6+
import { argv } from '@mx-space/compiled'
47

58
import { DEBUG_MODE } from './app.config'
69
import { registerForMemoryDump } from './dump'
@@ -51,7 +54,7 @@ async function main() {
5154
DEBUG_MODE.memoryDump && registerForMemoryDump()
5255
if (CLUSTER.enable) {
5356
Cluster.register(
54-
Number.parseInt(CLUSTER.workers) || os.cpus().length,
57+
Number.parseInt(CLUSTER.workers) || cpus().length,
5558
bootstrap,
5659
)
5760
} else {

apps/core/src/modules/ai/ai-agent/ai-agent.module.ts

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)