chore: migrate to oxlint and oxfmt
Co-authored-by: Christoph Nakazawa <christoph.pojer@gmail.com>
This commit is contained in:
@@ -103,8 +103,7 @@ describe("embedding provider remote overrides", () => {
|
||||
await result.provider.embedQuery("hello");
|
||||
|
||||
expect(authModule.resolveApiKeyForProvider).toHaveBeenCalledTimes(1);
|
||||
const headers =
|
||||
(fetchMock.mock.calls[0]?.[1]?.headers as Record<string, string>) ?? {};
|
||||
const headers = (fetchMock.mock.calls[0]?.[1]?.headers as Record<string, string>) ?? {};
|
||||
expect(headers.Authorization).toBe("Bearer provider-key");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -34,8 +34,7 @@ export type EmbeddingProviderOptions = {
|
||||
};
|
||||
|
||||
const DEFAULT_OPENAI_BASE_URL = "https://api.openai.com/v1";
|
||||
const DEFAULT_LOCAL_MODEL =
|
||||
"hf:ggml-org/embeddinggemma-300M-GGUF/embeddinggemma-300M-Q8_0.gguf";
|
||||
const DEFAULT_LOCAL_MODEL = "hf:ggml-org/embeddinggemma-300M-GGUF/embeddinggemma-300M-Q8_0.gguf";
|
||||
|
||||
function normalizeOpenAiModel(model: string): string {
|
||||
const trimmed = model.trim();
|
||||
@@ -60,14 +59,9 @@ async function createOpenAiEmbeddingProvider(
|
||||
});
|
||||
|
||||
const providerConfig = options.config.models?.providers?.openai;
|
||||
const baseUrl =
|
||||
remoteBaseUrl || providerConfig?.baseUrl?.trim() || DEFAULT_OPENAI_BASE_URL;
|
||||
const baseUrl = remoteBaseUrl || providerConfig?.baseUrl?.trim() || DEFAULT_OPENAI_BASE_URL;
|
||||
const url = `${baseUrl.replace(/\/$/, "")}/embeddings`;
|
||||
const headerOverrides = Object.assign(
|
||||
{},
|
||||
providerConfig?.headers,
|
||||
remote?.headers,
|
||||
);
|
||||
const headerOverrides = Object.assign({}, providerConfig?.headers, remote?.headers);
|
||||
const headers: Record<string, string> = {
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${apiKey}`,
|
||||
@@ -111,9 +105,7 @@ async function createLocalEmbeddingProvider(
|
||||
const modelCacheDir = options.local?.modelCacheDir?.trim();
|
||||
|
||||
// Lazy-load node-llama-cpp to keep startup light unless local is enabled.
|
||||
const { getLlama, resolveModelFile, LlamaLogLevel } = await import(
|
||||
"node-llama-cpp"
|
||||
);
|
||||
const { getLlama, resolveModelFile, LlamaLogLevel } = await import("node-llama-cpp");
|
||||
|
||||
let llama: Llama | null = null;
|
||||
let embeddingModel: LlamaModel | null = null;
|
||||
@@ -124,10 +116,7 @@ async function createLocalEmbeddingProvider(
|
||||
llama = await getLlama({ logLevel: LlamaLogLevel.error });
|
||||
}
|
||||
if (!embeddingModel) {
|
||||
const resolved = await resolveModelFile(
|
||||
modelPath,
|
||||
modelCacheDir || undefined,
|
||||
);
|
||||
const resolved = await resolveModelFile(modelPath, modelCacheDir || undefined);
|
||||
embeddingModel = await llama.loadModel({ modelPath: resolved });
|
||||
}
|
||||
if (!embeddingContext) {
|
||||
@@ -177,9 +166,7 @@ export async function createEmbeddingProvider(
|
||||
fallbackReason: reason,
|
||||
};
|
||||
} catch (fallbackErr) {
|
||||
throw new Error(
|
||||
`${reason}\n\nFallback to OpenAI failed: ${formatError(fallbackErr)}`,
|
||||
);
|
||||
throw new Error(`${reason}\n\nFallback to OpenAI failed: ${formatError(fallbackErr)}`);
|
||||
}
|
||||
}
|
||||
throw new Error(reason);
|
||||
|
||||
@@ -39,10 +39,7 @@ describe("memory index", () => {
|
||||
path.join(workspaceDir, "memory", "2026-01-12.md"),
|
||||
"# Log\nAlpha memory line.\nAnother line.",
|
||||
);
|
||||
await fs.writeFile(
|
||||
path.join(workspaceDir, "MEMORY.md"),
|
||||
"Beta knowledge base entry.",
|
||||
);
|
||||
await fs.writeFile(path.join(workspaceDir, "MEMORY.md"), "Beta knowledge base entry.");
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
@@ -98,8 +95,6 @@ describe("memory index", () => {
|
||||
expect(result.manager).not.toBeNull();
|
||||
if (!result.manager) throw new Error("manager missing");
|
||||
manager = result.manager;
|
||||
await expect(
|
||||
result.manager.readFile({ relPath: "NOTES.md" }),
|
||||
).rejects.toThrow("path required");
|
||||
await expect(result.manager.readFile({ relPath: "NOTES.md" })).rejects.toThrow("path required");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,8 +1,2 @@
|
||||
export {
|
||||
MemoryIndexManager,
|
||||
type MemorySearchResult,
|
||||
} from "./manager.js";
|
||||
export {
|
||||
getMemorySearchManager,
|
||||
type MemorySearchManagerResult,
|
||||
} from "./search-manager.js";
|
||||
export { MemoryIndexManager, type MemorySearchResult } from "./manager.js";
|
||||
export { getMemorySearchManager, type MemorySearchManagerResult } from "./search-manager.js";
|
||||
|
||||
@@ -4,10 +4,7 @@ import path from "node:path";
|
||||
import type { DatabaseSync } from "node:sqlite";
|
||||
import chokidar, { type FSWatcher } from "chokidar";
|
||||
|
||||
import {
|
||||
resolveAgentDir,
|
||||
resolveAgentWorkspaceDir,
|
||||
} from "../agents/agent-scope.js";
|
||||
import { resolveAgentDir, resolveAgentWorkspaceDir } from "../agents/agent-scope.js";
|
||||
import type { ResolvedMemorySearchConfig } from "../agents/memory-search.js";
|
||||
import { resolveMemorySearchConfig } from "../agents/memory-search.js";
|
||||
import type { ClawdbotConfig } from "../config/config.js";
|
||||
@@ -216,9 +213,7 @@ export class MemoryIndexManager {
|
||||
const files = this.db.prepare(`SELECT COUNT(*) as c FROM files`).get() as {
|
||||
c: number;
|
||||
};
|
||||
const chunks = this.db
|
||||
.prepare(`SELECT COUNT(*) as c FROM chunks`)
|
||||
.get() as {
|
||||
const chunks = this.db.prepare(`SELECT COUNT(*) as c FROM chunks`).get() as {
|
||||
c: number;
|
||||
};
|
||||
return {
|
||||
@@ -230,9 +225,7 @@ export class MemoryIndexManager {
|
||||
provider: this.provider.id,
|
||||
model: this.provider.model,
|
||||
requestedProvider: this.requestedProvider,
|
||||
fallback: this.fallbackReason
|
||||
? { from: "local", reason: this.fallbackReason }
|
||||
: undefined,
|
||||
fallback: this.fallbackReason ? { from: "local", reason: this.fallbackReason } : undefined,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -342,9 +335,7 @@ export class MemoryIndexManager {
|
||||
embedding: number[];
|
||||
}> {
|
||||
const rows = this.db
|
||||
.prepare(
|
||||
`SELECT path, start_line, end_line, text, embedding FROM chunks WHERE model = ?`,
|
||||
)
|
||||
.prepare(`SELECT path, start_line, end_line, text, embedding FROM chunks WHERE model = ?`)
|
||||
.all(this.provider.model) as Array<{
|
||||
path: string;
|
||||
start_line: number;
|
||||
@@ -381,9 +372,9 @@ export class MemoryIndexManager {
|
||||
const activePaths = new Set(fileEntries.map((entry) => entry.path));
|
||||
|
||||
for (const entry of fileEntries) {
|
||||
const record = this.db
|
||||
.prepare(`SELECT hash FROM files WHERE path = ?`)
|
||||
.get(entry.path) as { hash: string } | undefined;
|
||||
const record = this.db.prepare(`SELECT hash FROM files WHERE path = ?`).get(entry.path) as
|
||||
| { hash: string }
|
||||
| undefined;
|
||||
if (!needsFullReindex && record?.hash === entry.hash) {
|
||||
continue;
|
||||
}
|
||||
@@ -414,9 +405,9 @@ export class MemoryIndexManager {
|
||||
}
|
||||
|
||||
private readMeta(): MemoryIndexMeta | null {
|
||||
const row = this.db
|
||||
.prepare(`SELECT value FROM meta WHERE key = ?`)
|
||||
.get(META_KEY) as { value: string } | undefined;
|
||||
const row = this.db.prepare(`SELECT value FROM meta WHERE key = ?`).get(META_KEY) as
|
||||
| { value: string }
|
||||
| undefined;
|
||||
if (!row?.value) return null;
|
||||
try {
|
||||
return JSON.parse(row.value) as MemoryIndexMeta;
|
||||
@@ -437,9 +428,7 @@ export class MemoryIndexManager {
|
||||
private async indexFile(entry: MemoryFileEntry) {
|
||||
const content = await fs.readFile(entry.absPath, "utf-8");
|
||||
const chunks = chunkMarkdown(content, this.settings.chunking);
|
||||
const embeddings = await this.provider.embedBatch(
|
||||
chunks.map((chunk) => chunk.text),
|
||||
);
|
||||
const embeddings = await this.provider.embedBatch(chunks.map((chunk) => chunk.text));
|
||||
const now = Date.now();
|
||||
this.db.prepare(`DELETE FROM chunks WHERE path = ?`).run(entry.path);
|
||||
for (let i = 0; i < chunks.length; i++) {
|
||||
|
||||
Reference in New Issue
Block a user