mirror of
https://github.com/badlogic/pi-mono.git
synced 2026-11-05 23:37:25 +00:00
fix(agent): expose session stores through factories
This commit is contained in:
parent
2700511e45
commit
a1bb7e4483
12 changed files with 158 additions and 118 deletions
|
|
@ -7,13 +7,15 @@ import type {
|
|||
} from "@earendil-works/pi-agent-core";
|
||||
import {
|
||||
createSessionId,
|
||||
createSessionRepository,
|
||||
getEntriesToFork,
|
||||
getFileSystemResultOrThrow,
|
||||
SessionError,
|
||||
SessionRepository,
|
||||
type SessionRepository,
|
||||
type SessionStore,
|
||||
} from "@earendil-works/pi-agent-core";
|
||||
import { applyMigrations } from "./migrations.ts";
|
||||
import { SqliteSessionSearch } from "./search-backend.ts";
|
||||
import { createSqliteSessionSearch } from "./search-backend.ts";
|
||||
import { SqliteSessionStorage } from "./storage/index.ts";
|
||||
import { rowToMetadata, type SessionRow } from "./storage/sessions.ts";
|
||||
import type {
|
||||
|
|
@ -22,7 +24,6 @@ import type {
|
|||
SqliteSessionCreateOptions,
|
||||
SqliteSessionListOptions,
|
||||
SqliteSessionMetadata,
|
||||
SqliteSessionStoreApi,
|
||||
SqliteSessionStoreEnv,
|
||||
} from "./types.ts";
|
||||
|
||||
|
|
@ -51,7 +52,9 @@ export type SqliteSessionStoreOptions = {
|
|||
databasePath: string;
|
||||
};
|
||||
|
||||
export class SqliteSessionStore implements SqliteSessionStoreApi {
|
||||
class SqliteSessionStore
|
||||
implements SessionStore<SqliteSessionMetadata, SqliteSessionCreateOptions, SqliteSessionListOptions>
|
||||
{
|
||||
private readonly env: SqliteSessionStoreEnv;
|
||||
private readonly sqlite: SqliteDatabaseFactory;
|
||||
private readonly databasePathInput: string;
|
||||
|
|
@ -242,7 +245,9 @@ export class SqliteSessionStore implements SqliteSessionStoreApi {
|
|||
}
|
||||
}
|
||||
|
||||
export function createSqliteSessionStore(options: SqliteSessionStoreOptions): SqliteSessionStore {
|
||||
export function createSqliteSessionStore(
|
||||
options: SqliteSessionStoreOptions,
|
||||
): SessionStore<SqliteSessionMetadata, SqliteSessionCreateOptions, SqliteSessionListOptions> {
|
||||
return new SqliteSessionStore(options);
|
||||
}
|
||||
|
||||
|
|
@ -250,8 +255,8 @@ export function createSqliteSessionRepository(
|
|||
options: SqliteSessionStoreOptions,
|
||||
): SessionRepository<SqliteSessionMetadata, SqliteSessionCreateOptions, SqliteSessionListOptions> {
|
||||
const store = createSqliteSessionStore(options);
|
||||
return new SessionRepository({
|
||||
return createSessionRepository({
|
||||
store,
|
||||
search: new SqliteSessionSearch<SqliteSessionMetadata>({ ...options, mode: "canonical" }),
|
||||
search: createSqliteSessionSearch<SqliteSessionMetadata>({ ...options, mode: "canonical" }),
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -83,7 +83,7 @@ CREATE VIRTUAL TABLE IF NOT EXISTS session_search_fts USING fts5(
|
|||
* Storage-independent SQLite FTS search. Its database may be separate from,
|
||||
* or shared with, the canonical session backend.
|
||||
*/
|
||||
export class SqliteSessionSearch<TMetadata extends SessionMetadata = SessionMetadata>
|
||||
class SqliteSessionSearch<TMetadata extends SessionMetadata = SessionMetadata>
|
||||
implements SessionSearch<TMetadata>, SessionSearchIndex<TMetadata>
|
||||
{
|
||||
private readonly options: {
|
||||
|
|
@ -236,3 +236,9 @@ export class SqliteSessionSearch<TMetadata extends SessionMetadata = SessionMeta
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function createSqliteSessionSearch<TMetadata extends SessionMetadata = SessionMetadata>(
|
||||
options: SqliteSessionSearchOptions,
|
||||
): SessionSearch<TMetadata> & SessionSearchIndex<TMetadata> {
|
||||
return new SqliteSessionSearch<TMetadata>(options);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import type { FileSystem, SessionCreateOptions, SessionMetadata, SessionStore } from "@earendil-works/pi-agent-core";
|
||||
import type { FileSystem, SessionCreateOptions, SessionMetadata } from "@earendil-works/pi-agent-core";
|
||||
|
||||
/** Result of a prepared SQLite statement execution. */
|
||||
export interface SqliteRunResult {
|
||||
|
|
@ -44,7 +44,4 @@ export interface SqliteSessionListOptions {
|
|||
cwd?: string;
|
||||
}
|
||||
|
||||
export interface SqliteSessionStoreApi
|
||||
extends SessionStore<SqliteSessionMetadata, SqliteSessionCreateOptions, SqliteSessionListOptions> {}
|
||||
|
||||
export type SqliteSessionStoreEnv = Pick<FileSystem, "absolutePath" | "createDir" | "exists">;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue