diff --git a/.eslintrc.json b/.eslintrc.json deleted file mode 100644 index 49607f3..0000000 --- a/.eslintrc.json +++ /dev/null @@ -1,54 +0,0 @@ -{ - "env": { - "es2024": true - }, - "extends": [ - "eslint:recommended", - "plugin:unicorn/recommended", - "plugin:@typescript-eslint/strict-type-checked", - "plugin:@typescript-eslint/stylistic-type-checked" - ], - "plugins": ["@typescript-eslint", "unicorn"], - "parserOptions": { - "project": "./tsconfig.json" - }, - "ignorePatterns": ["*.config.*"], - "rules": { - "no-console": ["error", { "allow": ["warn", "error"] }], - "@typescript-eslint/no-magic-numbers": [ - "error", - { "ignore": [-1, 0, 1, 100], "ignoreArrayIndexes": true } - ], - "@typescript-eslint/unbound-method": "off", - "@typescript-eslint/prefer-as-const": "error", - "@typescript-eslint/consistent-type-imports": "error", - "@typescript-eslint/restrict-template-expressions": "off", - "@typescript-eslint/consistent-type-definitions": ["error", "type"], - "@typescript-eslint/no-unused-vars": [ - "error", - { "varsIgnorePattern": "^_", "argsIgnorePattern": "^_" } - ], - "@typescript-eslint/prefer-ts-expect-error": "off", - "@typescript-eslint/no-misused-promises": [ - "error", - { - "checksVoidReturn": false - } - ], - "unicorn/prevent-abbreviations": [ - 2, - { - "replacements": { - "args": false, - "props": false, - "db": false - } - } - ], - "no-implicit-coercion": ["error", { "boolean": true }], - "no-extra-boolean-cast": ["error", { "enforceForLogicalOperands": true }], - "no-unneeded-ternary": ["error", { "defaultAssignment": true }], - "unicorn/no-array-reduce": ["off"], - "unicorn/no-nested-ternary": "off" - } -} diff --git a/bun.lockb b/bun.lockb index 5cd75e6..97f5c35 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/eslint.config.mjs b/eslint.config.mjs new file mode 100644 index 0000000..7b006eb --- /dev/null +++ b/eslint.config.mjs @@ -0,0 +1,89 @@ +import typescriptEslint from "@typescript-eslint/eslint-plugin"; +import unicorn from "eslint-plugin-unicorn"; +import path from "node:path"; +import { fileURLToPath } from "node:url"; +import js from "@eslint/js"; +import { FlatCompat } from "@eslint/eslintrc"; + +const __filename = fileURLToPath(import.meta.url); +const __dirname = path.dirname(__filename); +const compat = new FlatCompat({ + baseDirectory: __dirname, + recommendedConfig: js.configs.recommended, + allConfig: js.configs.all +}); + +export default [{ + ignores: ["**/*.config.*"], +}, ...compat.extends( + "eslint:recommended", + "plugin:unicorn/recommended", + "plugin:@typescript-eslint/strict-type-checked", + "plugin:@typescript-eslint/stylistic-type-checked", +), { + plugins: { + "@typescript-eslint": typescriptEslint, + unicorn, + }, + + languageOptions: { + globals: {}, + ecmaVersion: 5, + sourceType: "script", + + parserOptions: { + project: "./tsconfig.json", + }, + }, + + rules: { + "no-console": ["error", { + allow: ["warn", "error"], + }], + + "@typescript-eslint/no-magic-numbers": ["error", { + ignore: [-1, 0, 1, 100], + ignoreArrayIndexes: true, + }], + + "@typescript-eslint/unbound-method": "off", + "@typescript-eslint/prefer-as-const": "error", + "@typescript-eslint/consistent-type-imports": "error", + "@typescript-eslint/restrict-template-expressions": "off", + "@typescript-eslint/consistent-type-definitions": ["error", "type"], + + "@typescript-eslint/no-unused-vars": ["error", { + varsIgnorePattern: "^_", + argsIgnorePattern: "^_", + }], + + "@typescript-eslint/prefer-ts-expect-error": "off", + + "@typescript-eslint/no-misused-promises": ["error", { + checksVoidReturn: false, + }], + + "unicorn/prevent-abbreviations": [2, { + replacements: { + args: false, + props: false, + db: false, + }, + }], + + "no-implicit-coercion": ["error", { + boolean: true, + }], + + "no-extra-boolean-cast": ["error", { + enforceForLogicalOperands: true, + }], + + "no-unneeded-ternary": ["error", { + defaultAssignment: true, + }], + + "unicorn/no-array-reduce": ["off"], + "unicorn/no-nested-ternary": "off", + }, +}]; \ No newline at end of file diff --git a/package.json b/package.json index b7a1d2c..730b424 100644 --- a/package.json +++ b/package.json @@ -47,11 +47,10 @@ "@commitlint/cli": "^19.2.2", "@commitlint/config-conventional": "^19.2.2", "@types/react": "^18.3.3", - "@typescript-eslint/eslint-plugin": "^7.0.1", - "@typescript-eslint/parser": "^7.0.1", + "@typescript-eslint/eslint-plugin": "^8.6.0", "bun-types": "latest", - "eslint": "^8", - "eslint-plugin-unicorn": "^51.0.1", + "eslint": "^9.10.0", + "eslint-plugin-unicorn": "^55.0.0", "husky": "^9.0.10", "prettier": "^3.2.5", "tsup": "latest", diff --git a/src/context-service/index.ts b/src/context-service/index.ts index e8610d1..e0a59bd 100644 --- a/src/context-service/index.ts +++ b/src/context-service/index.ts @@ -49,7 +49,7 @@ export class ContextService { return args.map((data) => this.add(data)); } - async deleteEntireContext(options?: ResetOptions | undefined) { + async deleteEntireContext(options?: ResetOptions ) { await this.#vectorService.reset( options?.namespace ? { namespace: options.namespace } : undefined ); diff --git a/src/database.ts b/src/database.ts index 9847a1d..edad8b8 100644 --- a/src/database.ts +++ b/src/database.ts @@ -84,7 +84,7 @@ export class Database { this.index = index; } - async reset(options?: ResetOptions | undefined) { + async reset(options?: ResetOptions ) { await this.index.reset({ namespace: options?.namespace }); } @@ -97,6 +97,7 @@ export class Database { * It takes care of the text-to-embedding conversion by itself. * Additionally, it lets consumers pass various options to tweak the output. */ + // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-parameters async retrieve({ question, similarityThreshold = DEFAULT_SIMILARITY_THRESHOLD, diff --git a/src/llm-service.ts b/src/llm-service.ts index afd7daf..d51c1d6 100644 --- a/src/llm-service.ts +++ b/src/llm-service.ts @@ -73,7 +73,7 @@ export class LLMService { let value: UpstashMessage | string | undefined; try { - // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition, no-constant-condition + // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition while (true) { ({ done, value } = await reader.read()); if (done) break; @@ -118,8 +118,8 @@ export class LLMService { }); content = text; } else { - const { content: text } = (await this.model.invoke(prompt)) as BaseMessage; - content = text; + const { content: output } = (await this.model.invoke(prompt)) as BaseMessage; + content = output; } onComplete?.(content as string); return { output: content as string, isStream: false }; diff --git a/src/logger.ts b/src/logger.ts index 064690d..866c2a1 100644 --- a/src/logger.ts +++ b/src/logger.ts @@ -1,5 +1,5 @@ -const LOG_LEVELS = ["DEBUG", "INFO", "WARN", "ERROR"] as const; -type LogLevel = (typeof LOG_LEVELS)[number]; +const _LOG_LEVELS = ["DEBUG", "INFO", "WARN", "ERROR"] as const; +type LogLevel = (typeof _LOG_LEVELS)[number]; type ChatLogEntry = { timestamp: number; diff --git a/src/models.ts b/src/models.ts index b89fc6c..efdc32d 100644 --- a/src/models.ts +++ b/src/models.ts @@ -162,7 +162,6 @@ const setupAnalytics = ( } default: { - // eslint-disable-next-line @typescript-eslint/no-explicit-any throw new Error(`Unsupported analytics provider: ${JSON.stringify(analytics)}`); } } @@ -217,7 +216,6 @@ export const openai = (model: OpenAIChatModel, options?: Omit { const streamData = new StreamData(); + // eslint-disable-next-line @typescript-eslint/no-deprecated const wrappedStream = LangChainAdapter.toAIStream(response.output, { onStart() { if (metadata) { diff --git a/src/rag-chat.test.ts b/src/rag-chat.test.ts index 034ce1d..5c7b9b1 100644 --- a/src/rag-chat.test.ts +++ b/src/rag-chat.test.ts @@ -25,7 +25,7 @@ async function checkStream( stream: ReadableStream, expectInStream: string[] // array of strings to expect in stream ): Promise { - const _stream = LangChainAdapter.toAIStream(stream); + const _stream = LangChainAdapter.toDataStream(stream); const textResponse = new StreamingTextResponse(_stream); const text = await textResponse.text(); diff --git a/src/types.ts b/src/types.ts index 14455f7..2f76eda 100644 --- a/src/types.ts +++ b/src/types.ts @@ -96,7 +96,6 @@ export type RAGChatConfig = { }) */ - // eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents model?: ChatOpenAI | ChatMistralAI | ChatAnthropic | OpenAIChatLanguageModel; /** * Ratelimit instance @@ -191,5 +190,4 @@ export type OpenAIChatLanguageModel = ReturnType; export type Prettify = { [K in keyof T]: T[K]; - // eslint-disable-next-line @typescript-eslint/ban-types } & {};