From 1dc9bb8d6217e1721a80a51e260b6fcaa2910166 Mon Sep 17 00:00:00 2001 From: cpojer Date: Tue, 17 Feb 2026 09:29:37 +0900 Subject: [PATCH] chore: Fix more type issues. --- src/memory/manager-embedding-ops.ts | 75 ++++++++++++++++++++++++++--- src/memory/manager.ts | 27 +++++------ 2 files changed, 81 insertions(+), 21 deletions(-) diff --git a/src/memory/manager-embedding-ops.ts b/src/memory/manager-embedding-ops.ts index 84120d96f82..ac241556be7 100644 --- a/src/memory/manager-embedding-ops.ts +++ b/src/memory/manager-embedding-ops.ts @@ -1,6 +1,7 @@ -// @ts-nocheck -// oxlint-disable eslint/no-unused-vars, typescript/no-explicit-any import fs from "node:fs/promises"; +import type { DatabaseSync } from "node:sqlite"; +import { type FSWatcher } from "chokidar"; +import type { ResolvedMemorySearchConfig } from "../agents/memory-search.js"; import { createSubsystemLogger } from "../logging/subsystem.js"; import { runGeminiEmbeddingBatches, type GeminiBatchRequest } from "./batch-gemini.js"; import { @@ -11,6 +12,12 @@ import { import { type VoyageBatchRequest, runVoyageEmbeddingBatches } from "./batch-voyage.js"; import { enforceEmbeddingMaxInputTokens } from "./embedding-chunk-limits.js"; import { estimateUtf8Bytes } from "./embedding-input-limits.js"; +import { + type EmbeddingProvider, + type GeminiEmbeddingClient, + type OpenAiEmbeddingClient, + type VoyageEmbeddingClient, +} from "./embeddings.js"; import { chunkMarkdown, hashText, @@ -41,8 +48,62 @@ const vectorToBlob = (embedding: number[]): Buffer => const log = createSubsystemLogger("memory"); -class MemoryManagerEmbeddingOps { - [key: string]: any; +abstract class MemoryManagerEmbeddingOps { + protected abstract readonly agentId: string; + protected abstract readonly workspaceDir: string; + protected abstract readonly settings: ResolvedMemorySearchConfig; + protected provider: EmbeddingProvider | null = null; + protected fallbackFrom?: "openai" | "local" | "gemini" | "voyage"; + protected openAi?: OpenAiEmbeddingClient; + protected gemini?: GeminiEmbeddingClient; + protected voyage?: VoyageEmbeddingClient; + protected abstract batch: { + enabled: boolean; + wait: boolean; + concurrency: number; + pollIntervalMs: number; + timeoutMs: number; + }; + protected readonly sources: Set = new Set(); + protected providerKey: string | null = null; + protected abstract readonly vector: { + enabled: boolean; + available: boolean | null; + extensionPath?: string; + loadError?: string; + dims?: number; + }; + protected readonly fts: { + enabled: boolean; + available: boolean; + loadError?: string; + } = { enabled: false, available: false }; + protected vectorReady: Promise | null = null; + protected watcher: FSWatcher | null = null; + protected watchTimer: NodeJS.Timeout | null = null; + protected sessionWatchTimer: NodeJS.Timeout | null = null; + protected sessionUnsubscribe: (() => void) | null = null; + protected fallbackReason?: string; + protected intervalTimer: NodeJS.Timeout | null = null; + protected closed = false; + protected dirty = false; + protected sessionsDirty = false; + protected sessionsDirtyFiles = new Set(); + protected sessionPendingFiles = new Set(); + protected sessionDeltas = new Map< + string, + { lastSize: number; pendingBytes: number; pendingMessages: number } + >(); + + protected batchFailureCount = 0; + protected batchFailureLastError?: string; + protected batchFailureLastProvider?: string; + protected batchFailureLock: Promise = Promise.resolve(); + + protected abstract readonly cache: { enabled: boolean; maxEntries?: number }; + protected abstract db: DatabaseSync; + protected abstract ensureVectorReady(dimensions?: number): Promise; + private buildEmbeddingBatches(chunks: MemoryChunk[]): MemoryChunk[][] { const batches: MemoryChunk[][] = []; let current: MemoryChunk[] = []; @@ -201,7 +262,7 @@ class MemoryManagerEmbeddingOps { return embeddings; } - private computeProviderKey(): string { + protected computeProviderKey(): string { // FTS-only mode: no provider, use a constant key if (!this.provider) { return hashText(JSON.stringify({ provider: "none", model: "fts-only" })); @@ -339,13 +400,13 @@ class MemoryManagerEmbeddingOps { chunks: MemoryChunk[]; source: MemorySource; }): { - agentId: string | undefined; + agentId: string; requests: TRequest[]; wait: boolean; concurrency: number; pollIntervalMs: number; timeoutMs: number; - debug: (message: string, data: Record) => void; + debug: (message: string, data?: Record) => void; } { const { requests, chunks, source } = params; return { diff --git a/src/memory/manager.ts b/src/memory/manager.ts index 9d86530fce6..2e28a07b48a 100644 --- a/src/memory/manager.ts +++ b/src/memory/manager.ts @@ -43,8 +43,8 @@ export class MemoryIndexManager implements MemorySearchManager { // oxlint-disable-next-line typescript/no-explicit-any [key: string]: any; private readonly cacheKey: string; - private readonly cfg: OpenClawConfig; - private readonly agentId: string; + protected readonly cfg: OpenClawConfig; + protected readonly agentId: string; private readonly workspaceDir: string; private readonly settings: ResolvedMemorySearchConfig; private provider: EmbeddingProvider | null; @@ -52,9 +52,9 @@ export class MemoryIndexManager implements MemorySearchManager { private fallbackFrom?: "openai" | "local" | "gemini" | "voyage"; private fallbackReason?: string; private readonly providerUnavailableReason?: string; - private openAi?: OpenAiEmbeddingClient; - private gemini?: GeminiEmbeddingClient; - private voyage?: VoyageEmbeddingClient; + protected openAi?: OpenAiEmbeddingClient; + protected gemini?: GeminiEmbeddingClient; + protected voyage?: VoyageEmbeddingClient; private batch: { enabled: boolean; wait: boolean; @@ -62,13 +62,12 @@ export class MemoryIndexManager implements MemorySearchManager { pollIntervalMs: number; timeoutMs: number; }; - private batchFailureCount = 0; - private batchFailureLastError?: string; - private batchFailureLastProvider?: string; - private batchFailureLock: Promise = Promise.resolve(); + protected batchFailureCount = 0; + protected batchFailureLastError?: string; + protected batchFailureLastProvider?: string; private db: DatabaseSync; private readonly sources: Set; - private providerKey: string; + protected providerKey: string; private readonly cache: { enabled: boolean; maxEntries?: number }; private readonly vector: { enabled: boolean; @@ -82,7 +81,7 @@ export class MemoryIndexManager implements MemorySearchManager { available: boolean; loadError?: string; }; - private vectorReady: Promise | null = null; + protected vectorReady: Promise | null = null; private watcher: FSWatcher | null = null; private watchTimer: NodeJS.Timeout | null = null; private sessionWatchTimer: NodeJS.Timeout | null = null; @@ -91,9 +90,9 @@ export class MemoryIndexManager implements MemorySearchManager { private closed = false; private dirty = false; private sessionsDirty = false; - private sessionsDirtyFiles = new Set(); - private sessionPendingFiles = new Set(); - private sessionDeltas = new Map< + protected sessionsDirtyFiles = new Set(); + protected sessionPendingFiles = new Set(); + protected sessionDeltas = new Map< string, { lastSize: number; pendingBytes: number; pendingMessages: number } >();