| export { createSession, listSessions, loadMemoryIntoSession, loadSession, saveSession, type Session, } from "../utils/session"; | ||
| export { repairJSON, safeParseJSON } from "../utils/json"; | ||
| export { type GrepMatch, grep } from "../utils/ripgrep"; | ||
| export { type Store, createFileStore, createStore } from "../utils/store"; | ||
| export { type Store, createStore } from "../utils/store"; |
+1
-1
| export { createSession, listSessions, loadMemoryIntoSession, loadSession, saveSession, type Session, } from "./utils/session"; | ||
| export { repairJSON, safeParseJSON } from "./utils/json"; | ||
| export { type GrepMatch, grep } from "./utils/ripgrep"; | ||
| export { type Store, createFileStore, createStore } from "./utils/store"; | ||
| export { type Store, createStore } from "./utils/store"; |
+1
-60
@@ -308,6 +308,2 @@ import { createRequire } from "node:module"; | ||
| // src/utils/store.ts | ||
| import { access, mkdir, readdir as readdir2, readFile as readFile2, writeFile } from "fs/promises"; | ||
| import { mkdirSync as mkdirSync2 } from "fs"; | ||
| import { join as join3, resolve } from "path"; | ||
| class Store { | ||
@@ -324,56 +320,2 @@ } | ||
| } | ||
| function createFileStore(options) { | ||
| const memoryDir = resolve(options.memoryDir ?? "./memory"); | ||
| mkdirSync2(memoryDir, { recursive: true }); | ||
| const memory = { | ||
| async read(name) { | ||
| const fullPath = safeJoin(memoryDir, name); | ||
| if (!fullPath) | ||
| return null; | ||
| try { | ||
| await access(fullPath); | ||
| return await readFile2(fullPath, "utf-8"); | ||
| } catch { | ||
| return null; | ||
| } | ||
| }, | ||
| async write(name, content) { | ||
| const fullPath = safeJoin(memoryDir, name); | ||
| if (!fullPath) | ||
| throw new Error("Invalid memory path"); | ||
| await mkdir(join3(fullPath, ".."), { recursive: true }); | ||
| await writeFile(fullPath, content, "utf-8"); | ||
| }, | ||
| async list() { | ||
| return readdirRecursive(memoryDir).then((files) => files.map((f) => f.slice(memoryDir.length + 1))); | ||
| } | ||
| }; | ||
| const session = { | ||
| save: (session2) => saveSession(session2, options), | ||
| load: (id) => loadSession(id, options), | ||
| list: () => listSessions(options).map((s) => ({ | ||
| id: s.id, | ||
| messages: [], | ||
| memoryLoaded: false, | ||
| createdAt: s.createdAt, | ||
| updatedAt: s.updatedAt | ||
| })) | ||
| }; | ||
| return createStore({ | ||
| memory, | ||
| session | ||
| }); | ||
| } | ||
| function safeJoin(base, name) { | ||
| const full = resolve(join3(base, name)); | ||
| return full.startsWith(base) ? full : null; | ||
| } | ||
| async function readdirRecursive(dir) { | ||
| const entries = await readdir2(dir, { withFileTypes: true }); | ||
| const results = await Promise.all(entries.map(async (e) => { | ||
| const full = join3(dir, e.name); | ||
| return e.isDirectory() ? readdirRecursive(full) : [full]; | ||
| })); | ||
| return results.flat(); | ||
| } | ||
| export { | ||
@@ -388,4 +330,3 @@ saveSession, | ||
| createStore, | ||
| createSession, | ||
| createFileStore | ||
| createSession | ||
| }; |
| import type { Session } from "./session"; | ||
| import { type SessionStoreOptions } from "./session"; | ||
| export interface MemoryStore { | ||
@@ -24,7 +23,1 @@ read(name: string): string | null | Promise<string | null>; | ||
| }; | ||
| export declare function createFileStore(options: SessionStoreOptions & { | ||
| memoryDir?: string; | ||
| }): { | ||
| memory: MemoryStore; | ||
| session: SessionStore; | ||
| }; |
+1
-1
| { | ||
| "name": "@ridit/ai", | ||
| "version": "0.1.81", | ||
| "version": "0.1.82", | ||
| "description": "Your agents, in minutes.", | ||
@@ -5,0 +5,0 @@ "author": "Ridit Jangra <riditjangra09@gmail.com> (https://ridit.space)", |
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 2 instances in 1 package
4
-33.33%3411985
-0.06%98145
-0.07%