refactor(agent): expose concrete harness session
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { randomUUID } from "node:crypto";
|
||||
import { readFileSync } from "node:fs";
|
||||
import type { ImageContent, Model } from "@mariozechner/pi-ai";
|
||||
import type { Agent } from "../agent.js";
|
||||
import { Agent } from "../agent.js";
|
||||
import type { AgentEvent, AgentMessage, AgentTool, ThinkingLevel } from "../types.js";
|
||||
import { collectEntriesForBranchSummary, generateBranchSummary } from "./compaction/branch-summarization.js";
|
||||
import { compact, DEFAULT_COMPACTION_SETTINGS, prepareCompaction } from "./compaction/compaction.js";
|
||||
@@ -68,7 +68,7 @@ export class DefaultAgentHarness implements AgentHarness {
|
||||
>();
|
||||
|
||||
constructor(options: AgentHarnessOptions) {
|
||||
this.agent = options.agent;
|
||||
this.agent = new Agent({});
|
||||
this.env = options.env;
|
||||
this.session = options.session;
|
||||
this.promptTemplates = options.promptTemplates ?? [];
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
import { DefaultAgentHarness } from "./agent-harness.js";
|
||||
import { DefaultSession } from "./session/session.js";
|
||||
import type { AgentHarness, AgentHarnessOptions, Session, SessionMetadata, SessionStorage } from "./types.js";
|
||||
import { Session } from "./session/session.js";
|
||||
import type { AgentHarness, AgentHarnessOptions, SessionMetadata, SessionStorage } from "./types.js";
|
||||
|
||||
export function createSession<TMetadata extends SessionMetadata>(
|
||||
storage: SessionStorage<TMetadata>,
|
||||
): Session<TMetadata> {
|
||||
return new DefaultSession(storage);
|
||||
return new Session(storage);
|
||||
}
|
||||
|
||||
export function createAgentHarness(options: AgentHarnessOptions): AgentHarness {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { v7 as uuidv7 } from "uuid";
|
||||
import type { Session, SessionMetadata, SessionStorage, SessionTreeEntry } from "../../types.js";
|
||||
import { DefaultSession } from "../session.js";
|
||||
import type { SessionMetadata, SessionStorage, SessionTreeEntry } from "../../types.js";
|
||||
import { Session } from "../session.js";
|
||||
|
||||
export function createSessionId(): string {
|
||||
return uuidv7();
|
||||
@@ -11,7 +11,7 @@ export function createTimestamp(): string {
|
||||
}
|
||||
|
||||
export function toSession<TMetadata extends SessionMetadata>(storage: SessionStorage<TMetadata>): Session<TMetadata> {
|
||||
return new DefaultSession(storage);
|
||||
return new Session(storage);
|
||||
}
|
||||
|
||||
export async function getEntriesToFork(
|
||||
|
||||
@@ -9,7 +9,6 @@ import type {
|
||||
LabelEntry,
|
||||
MessageEntry,
|
||||
ModelChangeEntry,
|
||||
Session,
|
||||
SessionContext,
|
||||
SessionInfoEntry,
|
||||
SessionMetadata,
|
||||
@@ -75,7 +74,7 @@ export function buildSessionContext(pathEntries: SessionTreeEntry[]): SessionCon
|
||||
return { messages, thinkingLevel, model };
|
||||
}
|
||||
|
||||
export class DefaultSession<TMetadata extends SessionMetadata = SessionMetadata> implements Session<TMetadata> {
|
||||
export class Session<TMetadata extends SessionMetadata = SessionMetadata> {
|
||||
private storage: SessionStorage<TMetadata>;
|
||||
|
||||
constructor(storage: SessionStorage<TMetadata>) {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import type { ImageContent, Model, TextContent } from "@mariozechner/pi-ai";
|
||||
import type { Agent, AgentEvent, AgentMessage, ThinkingLevel } from "../index.js";
|
||||
import type { Session } from "./session/session.js";
|
||||
|
||||
export type SourceScope = "user" | "project" | "temporary";
|
||||
export type SourceOrigin = "package" | "top-level";
|
||||
@@ -183,43 +184,7 @@ export interface SessionStorage<TMetadata extends SessionMetadata = SessionMetad
|
||||
getEntries(): Promise<SessionTreeEntry[]>;
|
||||
}
|
||||
|
||||
export interface Session<TMetadata extends SessionMetadata = SessionMetadata> {
|
||||
getMetadata(): Promise<TMetadata>;
|
||||
getStorage(): SessionStorage<TMetadata>;
|
||||
|
||||
getLeafId(): Promise<string | null>;
|
||||
getEntry(id: string): Promise<SessionTreeEntry | undefined>;
|
||||
getEntries(): Promise<SessionTreeEntry[]>;
|
||||
getBranch(fromId?: string): Promise<SessionTreeEntry[]>;
|
||||
buildContext(): Promise<SessionContext>;
|
||||
getLabel(id: string): Promise<string | undefined>;
|
||||
getSessionName(): Promise<string | undefined>;
|
||||
|
||||
appendMessage(message: AgentMessage): Promise<string>;
|
||||
appendThinkingLevelChange(thinkingLevel: string): Promise<string>;
|
||||
appendModelChange(provider: string, modelId: string): Promise<string>;
|
||||
appendCompaction<T = unknown>(
|
||||
summary: string,
|
||||
firstKeptEntryId: string,
|
||||
tokensBefore: number,
|
||||
details?: T,
|
||||
fromHook?: boolean,
|
||||
): Promise<string>;
|
||||
appendCustomEntry(customType: string, data?: unknown): Promise<string>;
|
||||
appendCustomMessageEntry<T = unknown>(
|
||||
customType: string,
|
||||
content: string | (TextContent | ImageContent)[],
|
||||
display: boolean,
|
||||
details?: T,
|
||||
): Promise<string>;
|
||||
appendLabel(targetId: string, label: string | undefined): Promise<string>;
|
||||
appendSessionName(name: string): Promise<string>;
|
||||
|
||||
moveTo(
|
||||
entryId: string | null,
|
||||
summary?: { summary: string; details?: unknown; fromHook?: boolean },
|
||||
): Promise<string | undefined>;
|
||||
}
|
||||
export type { Session } from "./session/session.js";
|
||||
|
||||
export interface SessionCreateOptions {
|
||||
id?: string;
|
||||
@@ -554,7 +519,6 @@ export interface BranchSummaryResult {
|
||||
}
|
||||
|
||||
export interface AgentHarnessOptions {
|
||||
agent: Agent;
|
||||
env: ExecutionEnv;
|
||||
session: Session;
|
||||
promptTemplates?: PromptTemplate[];
|
||||
|
||||
Reference in New Issue
Block a user