Commit 2dcb754f by Archer Committed by GitHub

fix: ts (#6890)

* fix: ts

* fix review
parent 23b5094b
...@@ -17,3 +17,5 @@ declare global { ...@@ -17,3 +17,5 @@ declare global {
var concatUsageHandler: (data: ConcatUsageProps) => any; var concatUsageHandler: (data: ConcatUsageProps) => any;
var pushUsageItemsHandler: (data: PushUsageItemsProps) => any; var pushUsageItemsHandler: (data: PushUsageItemsProps) => any;
} }
export {};
...@@ -7,7 +7,6 @@ import { ...@@ -7,7 +7,6 @@ import {
Worker, Worker,
type WorkerOptions type WorkerOptions
} from 'bullmq'; } from 'bullmq';
import './type';
import { getLogger, LogCategories } from '../logger'; import { getLogger, LogCategories } from '../logger';
import { newQueueRedisConnection, newWorkerRedisConnection } from '../redis'; import { newQueueRedisConnection, newWorkerRedisConnection } from '../redis';
import { delay } from '@fastgpt/global/common/system/utils'; import { delay } from '@fastgpt/global/common/system/utils';
......
import type { SystemCacheType } from './type';
declare global {
var systemCache: SystemCacheType;
}
export {};
...@@ -10,7 +10,7 @@ export type SystemCacheDataType = { ...@@ -10,7 +10,7 @@ export type SystemCacheDataType = {
[SystemCacheKeyEnum.modelPermission]: null; [SystemCacheKeyEnum.modelPermission]: null;
}; };
type SystemCacheType = { export type SystemCacheType = {
[K in SystemCacheKeyEnum]: { [K in SystemCacheKeyEnum]: {
versionKey: string; versionKey: string;
data: SystemCacheDataType[K]; data: SystemCacheDataType[K];
...@@ -18,7 +18,3 @@ type SystemCacheType = { ...@@ -18,7 +18,3 @@ type SystemCacheType = {
devRefresh?: boolean; devRefresh?: boolean;
}; };
}; };
declare global {
var systemCache: SystemCacheType;
}
import type { Mongoose } from 'mongoose'; import type { Mongoose } from 'mongoose';
import type { Logger } from 'winston';
declare global { declare global {
var mongodb: Mongoose | undefined; var mongodb: Mongoose | undefined;
var mongodbLog: Mongoose | undefined; var mongodbLog: Mongoose | undefined;
} }
export {};
...@@ -3,3 +3,5 @@ import type Redis from 'ioredis'; ...@@ -3,3 +3,5 @@ import type Redis from 'ioredis';
declare global { declare global {
var redisClient: Redis | null; var redisClient: Redis | null;
} }
export {};
import type { S3BaseBucket } from '../buckets/base';
declare global {
var s3BucketMap: {
[key: string]: S3BaseBucket;
};
}
export {};
import z from 'zod'; import z from 'zod';
import { Readable } from 'node:stream'; import { Readable } from 'node:stream';
import type { S3BaseBucket } from '../buckets/base';
export const S3MetadataSchema = z.object({ export const S3MetadataSchema = z.object({
filename: z.string(), filename: z.string(),
...@@ -87,9 +86,3 @@ export const UploadFileByBodySchema = z.object({ ...@@ -87,9 +86,3 @@ export const UploadFileByBodySchema = z.object({
}); });
export type UploadFileByBodyParams = z.infer<typeof UploadFileByBodySchema>; export type UploadFileByBodyParams = z.infer<typeof UploadFileByBodySchema>;
export type UploadFileByBufferParams = UploadFileByBodyParams; export type UploadFileByBufferParams = UploadFileByBodyParams;
declare global {
var s3BucketMap: {
[key: string]: S3BaseBucket;
};
}
import type { S3AvatarSource } from '.';
declare global {
var avatarBucket: S3AvatarSource;
}
export {};
import { S3Sources } from '../contracts/type';
import { MongoS3TTL } from '../models/ttl';
import { S3PublicBucket } from '../buckets/public';
import { avatarAllowedExtensions } from '../utils/uploadConstraints';
import { imageBaseUrl } from '@fastgpt/global/common/file/image/constants'; import { imageBaseUrl } from '@fastgpt/global/common/file/image/constants';
import type { ClientSession } from 'mongoose'; import type { ClientSession } from 'mongoose';
import { getFileS3Key } from '../utils'; import { getFileS3Key } from '../../utils';
import { MongoS3TTL } from '../../models/ttl';
import { S3PublicBucket } from '../../buckets/public';
import { avatarAllowedExtensions } from '../../utils/uploadConstraints';
class S3AvatarSource extends S3PublicBucket { class S3AvatarSource extends S3PublicBucket {
constructor() { constructor() {
...@@ -88,7 +87,3 @@ export function getS3AvatarSource() { ...@@ -88,7 +87,3 @@ export function getS3AvatarSource() {
global.avatarBucket = new S3AvatarSource(); global.avatarBucket = new S3AvatarSource();
return global.avatarBucket; return global.avatarBucket;
} }
declare global {
var avatarBucket: S3AvatarSource;
}
import type { S3ChatSource } from './index';
declare global {
var chatBucket: S3ChatSource;
}
export {};
...@@ -127,7 +127,3 @@ export function getS3ChatSource() { ...@@ -127,7 +127,3 @@ export function getS3ChatSource() {
global.chatBucket = new S3ChatSource(); global.chatBucket = new S3ChatSource();
return global.chatBucket; return global.chatBucket;
} }
declare global {
var chatBucket: S3ChatSource;
}
import type { S3DatasetSource } from './index';
declare global {
var datasetBucket: S3DatasetSource;
}
export {};
...@@ -188,7 +188,3 @@ export function getS3DatasetSource() { ...@@ -188,7 +188,3 @@ export function getS3DatasetSource() {
global.datasetBucket = new S3DatasetSource(); global.datasetBucket = new S3DatasetSource();
return global.datasetBucket; return global.datasetBucket;
} }
declare global {
var datasetBucket: S3DatasetSource;
}
import type { S3HelperBotSource } from './index';
declare global {
var helperBotBucket: S3HelperBotSource;
}
export {};
...@@ -100,7 +100,3 @@ export function getS3HelperBotSource() { ...@@ -100,7 +100,3 @@ export function getS3HelperBotSource() {
global.helperBotBucket = new S3HelperBotSource(); global.helperBotBucket = new S3HelperBotSource();
return global.helperBotBucket; return global.helperBotBucket;
} }
declare global {
var helperBotBucket: S3HelperBotSource;
}
import type { S3RawTextSource } from './index';
declare global {
var rawTextBucket: S3RawTextSource;
}
export {};
...@@ -81,7 +81,3 @@ export function getS3RawTextSource() { ...@@ -81,7 +81,3 @@ export function getS3RawTextSource() {
global.rawTextBucket = new S3RawTextSource(); global.rawTextBucket = new S3RawTextSource();
return global.rawTextBucket; return global.rawTextBucket;
} }
declare global {
var rawTextBucket: S3RawTextSource;
}
import type { Pool as PgPool } from 'pg';
import type { Pool as MysqlPool } from 'mysql2/promise';
import type { MilvusClient } from '@zilliz/milvus2-sdk-node';
declare global {
var pgClient: PgPool | null;
var obClient: MysqlPool | null;
var milvusClient: MilvusClient | null;
}
export {};
import type { Pool as PgPool } from 'pg';
import type { Pool as MysqlPool } from 'mysql2/promise';
import type { MilvusClient } from '@zilliz/milvus2-sdk-node';
import z from 'zod'; import z from 'zod';
// Embedding recall item schema // Embedding recall item schema
...@@ -115,9 +112,3 @@ export interface VectorControllerType { ...@@ -115,9 +112,3 @@ export interface VectorControllerType {
*/ */
getVectorCount(props: GetVectorCountPropsType): Promise<number>; getVectorCount(props: GetVectorCountPropsType): Promise<number>;
} }
declare global {
var pgClient: PgPool | null;
var obClient: MysqlPool | null;
var milvusClient: MilvusClient | null;
}
...@@ -93,7 +93,7 @@ export const createLLMResponse = async <T extends ChatCompletionCreateParams>( ...@@ -93,7 +93,7 @@ export const createLLMResponse = async <T extends ChatCompletionCreateParams>(
const requestMessages = await loadRequestMessages({ const requestMessages = await loadRequestMessages({
messages, messages,
useVision: useVision && model.vision, useVision: useVision && model.vision,
origin: requestOrigin supportReason: model.reasoning
}); });
// Message process // Message process
const rewriteMessages = (() => { const rewriteMessages = (() => {
...@@ -102,7 +102,8 @@ export const createLLMResponse = async <T extends ChatCompletionCreateParams>( ...@@ -102,7 +102,8 @@ export const createLLMResponse = async <T extends ChatCompletionCreateParams>(
} }
return requestMessages; return requestMessages;
})(); })();
// console.log(23232323);
// console.dir(rewriteMessages, { depth: null });
const { requestBody, modelData } = await llmCompletionsBodyFormat({ const { requestBody, modelData } = await llmCompletionsBodyFormat({
...body, ...body,
messages: rewriteMessages messages: rewriteMessages
......
...@@ -95,11 +95,11 @@ export const filterGPTMessageByMaxContext = async ({ ...@@ -95,11 +95,11 @@ export const filterGPTMessageByMaxContext = async ({
export const loadRequestMessages = async ({ export const loadRequestMessages = async ({
messages, messages,
useVision = false, useVision = false,
origin supportReason = false
}: { }: {
messages: ChatCompletionMessageParam[]; messages: ChatCompletionMessageParam[];
useVision?: boolean; useVision?: boolean;
origin?: string; supportReason?: boolean;
}) => { }) => {
const parseSystemMessage = ( const parseSystemMessage = (
content: string | ChatCompletionContentPartText[] content: string | ChatCompletionContentPartText[]
...@@ -265,12 +265,13 @@ export const loadRequestMessages = async ({ ...@@ -265,12 +265,13 @@ export const loadRequestMessages = async ({
const formatAssistantItem = ( const formatAssistantItem = (
item: ChatCompletionAssistantMessageParam & { item: ChatCompletionAssistantMessageParam & {
reasoning_content?: string; reasoning_content?: string;
} },
supportReason: boolean
) => { ) => {
return { return {
role: item.role, role: item.role,
content: item.content || undefined, content: item.content || undefined,
reasoning_content: item.reasoning_content || undefined, reasoning_content: supportReason ? item.reasoning_content || undefined : undefined,
function_call: item.function_call || undefined, function_call: item.function_call || undefined,
name: item.name || undefined, name: item.name || undefined,
refusal: item.refusal || undefined, refusal: item.refusal || undefined,
...@@ -411,8 +412,8 @@ export const loadRequestMessages = async ({ ...@@ -411,8 +412,8 @@ export const loadRequestMessages = async ({
: (formatContent as ChatCompletionContentPartText[]) : (formatContent as ChatCompletionContentPartText[])
}; };
} else if (item.role === ChatCompletionRequestMessageRoleEnum.Assistant) { } else if (item.role === ChatCompletionRequestMessageRoleEnum.Assistant) {
if (item.tool_calls || item.function_call || item.reasoning_content) { if (item.tool_calls || item.function_call) {
return formatAssistantItem(item); return formatAssistantItem(item, supportReason);
} }
const parseContent = parseAssistantContent(item.content); const parseContent = parseAssistantContent(item.content);
...@@ -433,7 +434,7 @@ export const loadRequestMessages = async ({ ...@@ -433,7 +434,7 @@ export const loadRequestMessages = async ({
if (!formatContent) return; if (!formatContent) return;
return { return {
...formatAssistantItem(item), ...formatAssistantItem(item, supportReason),
content: formatContent content: formatContent
}; };
} else { } else {
......
...@@ -52,3 +52,5 @@ declare global { ...@@ -52,3 +52,5 @@ declare global {
var systemActiveDesensitizedModels: SystemModelItemType[]; var systemActiveDesensitizedModels: SystemModelItemType[];
var systemDefaultModel: SystemDefaultModelType; var systemDefaultModel: SystemDefaultModelType;
} }
export {};
import type { AppTemplateSchemaType } from '@fastgpt/global/core/app/type';
declare global {
var appTemplates: AppTemplateSchemaType[];
var templatesRefreshTime: number;
}
export {};
...@@ -74,8 +74,3 @@ export const getAppTemplatesAndLoadThem = async (refresh = false) => { ...@@ -74,8 +74,3 @@ export const getAppTemplatesAndLoadThem = async (refresh = false) => {
export const isCommercialTemaplte = (templateId: string) => { export const isCommercialTemaplte = (templateId: string) => {
return templateId.startsWith(AppToolSourceEnum.commercial); return templateId.startsWith(AppToolSourceEnum.commercial);
}; };
declare global {
var appTemplates: AppTemplateSchemaType[];
var templatesRefreshTime: number;
}
...@@ -85,6 +85,7 @@ ...@@ -85,6 +85,7 @@
"@types/lodash": "catalog:", "@types/lodash": "catalog:",
"@types/mime-types": "catalog:", "@types/mime-types": "catalog:",
"@types/multer": "^1.4.10", "@types/multer": "^1.4.10",
"@types/node": "catalog:",
"@types/node-cron": "^3.0.11", "@types/node-cron": "^3.0.11",
"@types/papaparse": "5.3.7", "@types/papaparse": "5.3.7",
"@types/pg": "^8.6.6", "@types/pg": "^8.6.6",
......
...@@ -3,5 +3,5 @@ ...@@ -3,5 +3,5 @@
"compilerOptions": { "compilerOptions": {
"moduleResolution": "bundler" "moduleResolution": "bundler"
}, },
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx"] "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", "**/*.d.ts"]
} }
...@@ -632,6 +632,9 @@ importers: ...@@ -632,6 +632,9 @@ importers:
'@types/multer': '@types/multer':
specifier: ^1.4.10 specifier: ^1.4.10
version: 1.4.12 version: 1.4.12
'@types/node':
specifier: 'catalog:'
version: 20.17.24
'@types/node-cron': '@types/node-cron':
specifier: ^3.0.11 specifier: ^3.0.11
version: 3.0.11 version: 3.0.11
......
Subproject commit ee1b1d779dfa90b36503d0693c97437fd9ba7b6a Subproject commit 1dc6ead607f6b519226d79fcbc95dfe219e6606e
...@@ -28,6 +28,6 @@ ...@@ -28,6 +28,6 @@
"#fastgpt/app/test/*": ["./*"], "#fastgpt/app/test/*": ["./*"],
} }
}, },
"include": ["**/*.test.ts"], "include": ["**/*.test.ts", "../../../packages/service/**/*.d.ts"],
"exclude": ["**/node_modules"] "exclude": ["**/node_modules"]
} }
...@@ -13,7 +13,8 @@ ...@@ -13,7 +13,8 @@
"**/*.ts", "**/*.ts",
"**/*.tsx", "**/*.tsx",
"../../packages/**/*.ts", "../../packages/**/*.ts",
"../../packages/**/*.tsx" "../../packages/**/*.tsx",
"../../packages/**/*.d.ts"
], ],
"exclude": [ "exclude": [
"**/*.test.ts", "**/*.test.ts",
......
...@@ -28,6 +28,6 @@ ...@@ -28,6 +28,6 @@
"#fastgpt/marketplace/test/*": ["./*"], "#fastgpt/marketplace/test/*": ["./*"],
} }
}, },
"include": ["**/*.test.ts"], "include": ["**/*.test.ts", "../../../packages/service/**/*.d.ts"],
"exclude": ["**/node_modules"] "exclude": ["**/node_modules"]
} }
...@@ -6,7 +6,13 @@ ...@@ -6,7 +6,13 @@
"@/*": ["./src/*"] "@/*": ["./src/*"]
} }
}, },
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", "../../packages/**/*.ts"], "include": [
"next-env.d.ts",
"**/*.ts",
"**/*.tsx",
"../../packages/**/*.ts",
"../../packages/**/*.d.ts"
],
"exclude": [ "exclude": [
"**/*.test.ts", "**/*.test.ts",
"../../packages/**/vitest.config.ts", "../../packages/**/vitest.config.ts",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment