From 7009925585226fd6cd523c19ca1e06133c0498cf Mon Sep 17 00:00:00 2001 From: Zero Liu Date: Thu, 14 May 2026 00:53:06 -0700 Subject: [PATCH] chore(types): tighten any types and fix langchain getType deprecation (#2444) * chore(types): tighten any types and fix langchain getType deprecation - Replace `message.getType()` with `message.type` in BedrockChatModel - Type `docToSave` as `OramaDocument` and `explanation` as `SearchExplanation` - Extract a typed `fallbackMetadata` to avoid `any` union warnings Co-Authored-By: Claude Opus 4.7 (1M context) * fix(lint): drop unnecessary `as unknown` cast on upsert return Now that `docToSave` is typed as `OramaDocument`, it's already assignable to the `Promise` return type without an explicit cast. Co-Authored-By: Claude Opus 4.7 (1M context) --------- Co-authored-by: Claude Opus 4.7 (1M context) --- src/LLMProviders/BedrockChatModel.ts | 7 ++++--- src/search/dbOperations.ts | 4 ++-- src/search/v3/utils/ScoreNormalizer.ts | 8 ++++++-- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/LLMProviders/BedrockChatModel.ts b/src/LLMProviders/BedrockChatModel.ts index 22c8fabf..f8dabc7a 100644 --- a/src/LLMProviders/BedrockChatModel.ts +++ b/src/LLMProviders/BedrockChatModel.ts @@ -391,13 +391,14 @@ export class BedrockChatModel extends BaseChatModel const fallback = await this._generate(messages, options, runManager); const fallbackText = fallback.generations[0]?.text ?? ""; if (fallbackText) { + const fallbackMetadata: Record = fallback.llmOutput ?? {}; yield new ChatGenerationChunk({ message: new AIMessageChunk({ content: fallbackText, - response_metadata: fallback.llmOutput ?? {}, + response_metadata: fallbackMetadata, }), text: fallbackText, - generationInfo: fallback.llmOutput ?? {}, + generationInfo: fallbackMetadata, }); } } @@ -1251,7 +1252,7 @@ export class BedrockChatModel extends BaseChatModel const systemPrompts: string[] = []; messages.forEach((message) => { - const messageType = message.getType(); + const messageType = message.type; // Handle system messages (always text-only) if (messageType === "system") { diff --git a/src/search/dbOperations.ts b/src/search/dbOperations.ts index 066b98b5..484dbc22 100644 --- a/src/search/dbOperations.ts +++ b/src/search/dbOperations.ts @@ -368,7 +368,7 @@ export class DBOperations { }; } - async upsert(docToSave: any): Promise { + async upsert(docToSave: OramaDocument): Promise { if (!this.oramaDb) throw new Error("DB not initialized"); const db = this.oramaDb; @@ -400,7 +400,7 @@ export class DBOperations { ); this.markUnsavedChanges(); - return docToSave as unknown; + return docToSave; } catch (insertErr) { logError( `Failed to ${existingDoc.hits.length > 0 ? "update" : "insert"} document ${docToSave.id}:`, diff --git a/src/search/v3/utils/ScoreNormalizer.ts b/src/search/v3/utils/ScoreNormalizer.ts index a4e348ff..7e736e9c 100644 --- a/src/search/v3/utils/ScoreNormalizer.ts +++ b/src/search/v3/utils/ScoreNormalizer.ts @@ -1,4 +1,4 @@ -import { NoteIdRank } from "../interfaces"; +import { NoteIdRank, SearchExplanation } from "../interfaces"; /** * Configuration for score normalization @@ -29,7 +29,11 @@ export class ScoreNormalizer { /** * Update explanation with normalized scores */ - private updateExplanation(explanation: any, originalScore: number, normalizedScore: number): any { + private updateExplanation( + explanation: SearchExplanation | undefined, + originalScore: number, + normalizedScore: number + ): SearchExplanation | undefined { if (!explanation) return undefined; return {