mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-11 02:34:32 +00:00
chore: Fix more type issues.
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
// @ts-nocheck
|
|
||||||
// oxlint-disable eslint/no-unused-vars, typescript/no-explicit-any
|
|
||||||
import fs from "node:fs/promises";
|
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 { createSubsystemLogger } from "../logging/subsystem.js";
|
||||||
import { runGeminiEmbeddingBatches, type GeminiBatchRequest } from "./batch-gemini.js";
|
import { runGeminiEmbeddingBatches, type GeminiBatchRequest } from "./batch-gemini.js";
|
||||||
import {
|
import {
|
||||||
@@ -11,6 +12,12 @@ import {
|
|||||||
import { type VoyageBatchRequest, runVoyageEmbeddingBatches } from "./batch-voyage.js";
|
import { type VoyageBatchRequest, runVoyageEmbeddingBatches } from "./batch-voyage.js";
|
||||||
import { enforceEmbeddingMaxInputTokens } from "./embedding-chunk-limits.js";
|
import { enforceEmbeddingMaxInputTokens } from "./embedding-chunk-limits.js";
|
||||||
import { estimateUtf8Bytes } from "./embedding-input-limits.js";
|
import { estimateUtf8Bytes } from "./embedding-input-limits.js";
|
||||||
|
import {
|
||||||
|
type EmbeddingProvider,
|
||||||
|
type GeminiEmbeddingClient,
|
||||||
|
type OpenAiEmbeddingClient,
|
||||||
|
type VoyageEmbeddingClient,
|
||||||
|
} from "./embeddings.js";
|
||||||
import {
|
import {
|
||||||
chunkMarkdown,
|
chunkMarkdown,
|
||||||
hashText,
|
hashText,
|
||||||
@@ -41,8 +48,62 @@ const vectorToBlob = (embedding: number[]): Buffer =>
|
|||||||
|
|
||||||
const log = createSubsystemLogger("memory");
|
const log = createSubsystemLogger("memory");
|
||||||
|
|
||||||
class MemoryManagerEmbeddingOps {
|
abstract class MemoryManagerEmbeddingOps {
|
||||||
[key: string]: any;
|
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<MemorySource> = 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<boolean> | 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<string>();
|
||||||
|
protected sessionPendingFiles = new Set<string>();
|
||||||
|
protected sessionDeltas = new Map<
|
||||||
|
string,
|
||||||
|
{ lastSize: number; pendingBytes: number; pendingMessages: number }
|
||||||
|
>();
|
||||||
|
|
||||||
|
protected batchFailureCount = 0;
|
||||||
|
protected batchFailureLastError?: string;
|
||||||
|
protected batchFailureLastProvider?: string;
|
||||||
|
protected batchFailureLock: Promise<void> = Promise.resolve();
|
||||||
|
|
||||||
|
protected abstract readonly cache: { enabled: boolean; maxEntries?: number };
|
||||||
|
protected abstract db: DatabaseSync;
|
||||||
|
protected abstract ensureVectorReady(dimensions?: number): Promise<boolean>;
|
||||||
|
|
||||||
private buildEmbeddingBatches(chunks: MemoryChunk[]): MemoryChunk[][] {
|
private buildEmbeddingBatches(chunks: MemoryChunk[]): MemoryChunk[][] {
|
||||||
const batches: MemoryChunk[][] = [];
|
const batches: MemoryChunk[][] = [];
|
||||||
let current: MemoryChunk[] = [];
|
let current: MemoryChunk[] = [];
|
||||||
@@ -201,7 +262,7 @@ class MemoryManagerEmbeddingOps {
|
|||||||
return embeddings;
|
return embeddings;
|
||||||
}
|
}
|
||||||
|
|
||||||
private computeProviderKey(): string {
|
protected computeProviderKey(): string {
|
||||||
// FTS-only mode: no provider, use a constant key
|
// FTS-only mode: no provider, use a constant key
|
||||||
if (!this.provider) {
|
if (!this.provider) {
|
||||||
return hashText(JSON.stringify({ provider: "none", model: "fts-only" }));
|
return hashText(JSON.stringify({ provider: "none", model: "fts-only" }));
|
||||||
@@ -339,13 +400,13 @@ class MemoryManagerEmbeddingOps {
|
|||||||
chunks: MemoryChunk[];
|
chunks: MemoryChunk[];
|
||||||
source: MemorySource;
|
source: MemorySource;
|
||||||
}): {
|
}): {
|
||||||
agentId: string | undefined;
|
agentId: string;
|
||||||
requests: TRequest[];
|
requests: TRequest[];
|
||||||
wait: boolean;
|
wait: boolean;
|
||||||
concurrency: number;
|
concurrency: number;
|
||||||
pollIntervalMs: number;
|
pollIntervalMs: number;
|
||||||
timeoutMs: number;
|
timeoutMs: number;
|
||||||
debug: (message: string, data: Record<string, unknown>) => void;
|
debug: (message: string, data?: Record<string, unknown>) => void;
|
||||||
} {
|
} {
|
||||||
const { requests, chunks, source } = params;
|
const { requests, chunks, source } = params;
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -43,8 +43,8 @@ export class MemoryIndexManager implements MemorySearchManager {
|
|||||||
// oxlint-disable-next-line typescript/no-explicit-any
|
// oxlint-disable-next-line typescript/no-explicit-any
|
||||||
[key: string]: any;
|
[key: string]: any;
|
||||||
private readonly cacheKey: string;
|
private readonly cacheKey: string;
|
||||||
private readonly cfg: OpenClawConfig;
|
protected readonly cfg: OpenClawConfig;
|
||||||
private readonly agentId: string;
|
protected readonly agentId: string;
|
||||||
private readonly workspaceDir: string;
|
private readonly workspaceDir: string;
|
||||||
private readonly settings: ResolvedMemorySearchConfig;
|
private readonly settings: ResolvedMemorySearchConfig;
|
||||||
private provider: EmbeddingProvider | null;
|
private provider: EmbeddingProvider | null;
|
||||||
@@ -52,9 +52,9 @@ export class MemoryIndexManager implements MemorySearchManager {
|
|||||||
private fallbackFrom?: "openai" | "local" | "gemini" | "voyage";
|
private fallbackFrom?: "openai" | "local" | "gemini" | "voyage";
|
||||||
private fallbackReason?: string;
|
private fallbackReason?: string;
|
||||||
private readonly providerUnavailableReason?: string;
|
private readonly providerUnavailableReason?: string;
|
||||||
private openAi?: OpenAiEmbeddingClient;
|
protected openAi?: OpenAiEmbeddingClient;
|
||||||
private gemini?: GeminiEmbeddingClient;
|
protected gemini?: GeminiEmbeddingClient;
|
||||||
private voyage?: VoyageEmbeddingClient;
|
protected voyage?: VoyageEmbeddingClient;
|
||||||
private batch: {
|
private batch: {
|
||||||
enabled: boolean;
|
enabled: boolean;
|
||||||
wait: boolean;
|
wait: boolean;
|
||||||
@@ -62,13 +62,12 @@ export class MemoryIndexManager implements MemorySearchManager {
|
|||||||
pollIntervalMs: number;
|
pollIntervalMs: number;
|
||||||
timeoutMs: number;
|
timeoutMs: number;
|
||||||
};
|
};
|
||||||
private batchFailureCount = 0;
|
protected batchFailureCount = 0;
|
||||||
private batchFailureLastError?: string;
|
protected batchFailureLastError?: string;
|
||||||
private batchFailureLastProvider?: string;
|
protected batchFailureLastProvider?: string;
|
||||||
private batchFailureLock: Promise<void> = Promise.resolve();
|
|
||||||
private db: DatabaseSync;
|
private db: DatabaseSync;
|
||||||
private readonly sources: Set<MemorySource>;
|
private readonly sources: Set<MemorySource>;
|
||||||
private providerKey: string;
|
protected providerKey: string;
|
||||||
private readonly cache: { enabled: boolean; maxEntries?: number };
|
private readonly cache: { enabled: boolean; maxEntries?: number };
|
||||||
private readonly vector: {
|
private readonly vector: {
|
||||||
enabled: boolean;
|
enabled: boolean;
|
||||||
@@ -82,7 +81,7 @@ export class MemoryIndexManager implements MemorySearchManager {
|
|||||||
available: boolean;
|
available: boolean;
|
||||||
loadError?: string;
|
loadError?: string;
|
||||||
};
|
};
|
||||||
private vectorReady: Promise<boolean> | null = null;
|
protected vectorReady: Promise<boolean> | null = null;
|
||||||
private watcher: FSWatcher | null = null;
|
private watcher: FSWatcher | null = null;
|
||||||
private watchTimer: NodeJS.Timeout | null = null;
|
private watchTimer: NodeJS.Timeout | null = null;
|
||||||
private sessionWatchTimer: NodeJS.Timeout | null = null;
|
private sessionWatchTimer: NodeJS.Timeout | null = null;
|
||||||
@@ -91,9 +90,9 @@ export class MemoryIndexManager implements MemorySearchManager {
|
|||||||
private closed = false;
|
private closed = false;
|
||||||
private dirty = false;
|
private dirty = false;
|
||||||
private sessionsDirty = false;
|
private sessionsDirty = false;
|
||||||
private sessionsDirtyFiles = new Set<string>();
|
protected sessionsDirtyFiles = new Set<string>();
|
||||||
private sessionPendingFiles = new Set<string>();
|
protected sessionPendingFiles = new Set<string>();
|
||||||
private sessionDeltas = new Map<
|
protected sessionDeltas = new Map<
|
||||||
string,
|
string,
|
||||||
{ lastSize: number; pendingBytes: number; pendingMessages: number }
|
{ lastSize: number; pendingBytes: number; pendingMessages: number }
|
||||||
>();
|
>();
|
||||||
|
|||||||
Reference in New Issue
Block a user