mirror of
https://github.com/siteboon/claudecodeui.git
synced 2026-04-21 13:01:31 +00:00
refactor(cursor): lazy-load better-sqlite3 and remove unused type definitions
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import crypto from 'node:crypto';
|
||||
import { createRequire } from 'node:module';
|
||||
import os from 'node:os';
|
||||
import path from 'node:path';
|
||||
|
||||
@@ -11,22 +10,9 @@ import type { FetchHistoryOptions, FetchHistoryResult, NormalizedMessage } from
|
||||
import { createNormalizedMessage, generateMessageId, readObjectRecord } from '@/shared/utils.js';
|
||||
|
||||
const PROVIDER = 'cursor';
|
||||
const nodeRequire = createRequire(import.meta.url);
|
||||
|
||||
type RawProviderMessage = Record<string, any>;
|
||||
|
||||
type BetterSqliteDatabase = {
|
||||
prepare(sql: string): {
|
||||
all(): CursorDbBlob[];
|
||||
};
|
||||
close(): void;
|
||||
};
|
||||
|
||||
type BetterSqliteConstructor = new (
|
||||
filename: string,
|
||||
options: { readonly: boolean; fileMustExist: boolean },
|
||||
) => BetterSqliteDatabase;
|
||||
|
||||
type CursorDbBlob = {
|
||||
rowid: number;
|
||||
id: string;
|
||||
@@ -61,7 +47,8 @@ export class CursorProvider extends AbstractProvider {
|
||||
* order. Cursor history is stored as content-addressed blobs rather than JSONL.
|
||||
*/
|
||||
private async loadCursorBlobs(sessionId: string, projectPath: string): Promise<CursorMessageBlob[]> {
|
||||
const Database = nodeRequire('better-sqlite3') as BetterSqliteConstructor;
|
||||
// Lazy-import better-sqlite3 so the module doesn't fail if it's unavailable
|
||||
const { default: Database } = await import('better-sqlite3');
|
||||
|
||||
const cwdId = crypto.createHash('md5').update(projectPath || process.cwd()).digest('hex');
|
||||
const storeDbPath = path.join(os.homedir(), '.cursor', 'chats', cwdId, sessionId, 'store.db');
|
||||
@@ -69,7 +56,7 @@ export class CursorProvider extends AbstractProvider {
|
||||
const db = new Database(storeDbPath, { readonly: true, fileMustExist: true });
|
||||
|
||||
try {
|
||||
const allBlobs = db.prepare('SELECT rowid, id, data FROM blobs').all();
|
||||
const allBlobs = db.prepare<[], CursorDbBlob>('SELECT rowid, id, data FROM blobs').all();
|
||||
|
||||
const blobMap = new Map<string, CursorDbBlob>();
|
||||
const parentRefs = new Map<string, string[]>();
|
||||
|
||||
Reference in New Issue
Block a user