feat(agent): add harness factory helpers
This commit is contained in:
13
packages/agent/src/harness/factory.ts
Normal file
13
packages/agent/src/harness/factory.ts
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
import { DefaultAgentHarness } from "./agent-harness.js";
|
||||||
|
import { DefaultSession } from "./session/session.js";
|
||||||
|
import type { AgentHarness, AgentHarnessOptions, Session, SessionMetadata, SessionStorage } from "./types.js";
|
||||||
|
|
||||||
|
export function createSession<TMetadata extends SessionMetadata>(
|
||||||
|
storage: SessionStorage<TMetadata>,
|
||||||
|
): Session<TMetadata> {
|
||||||
|
return new DefaultSession(storage);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function createAgentHarness(options: AgentHarnessOptions): AgentHarness {
|
||||||
|
return new DefaultAgentHarness(options);
|
||||||
|
}
|
||||||
@@ -23,6 +23,7 @@ export {
|
|||||||
shouldCompact,
|
shouldCompact,
|
||||||
} from "./harness/compaction/compaction.js";
|
} from "./harness/compaction/compaction.js";
|
||||||
export * from "./harness/execution-env.js";
|
export * from "./harness/execution-env.js";
|
||||||
|
export * from "./harness/factory.js";
|
||||||
export * from "./harness/messages.js";
|
export * from "./harness/messages.js";
|
||||||
export * from "./harness/prompt-templates.js";
|
export * from "./harness/prompt-templates.js";
|
||||||
export * from "./harness/session/repo/jsonl.js";
|
export * from "./harness/session/repo/jsonl.js";
|
||||||
|
|||||||
25
packages/agent/test/harness/factory.test.ts
Normal file
25
packages/agent/test/harness/factory.test.ts
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
import { describe, expect, it } from "vitest";
|
||||||
|
import { Agent } from "../../src/agent.js";
|
||||||
|
import { NodeExecutionEnv } from "../../src/harness/execution-env.js";
|
||||||
|
import { createAgentHarness, createSession } from "../../src/harness/factory.js";
|
||||||
|
import { InMemorySessionStorage } from "../../src/harness/session/storage/memory.js";
|
||||||
|
|
||||||
|
describe("harness factories", () => {
|
||||||
|
it("creates sessions from storage", async () => {
|
||||||
|
const storage = new InMemorySessionStorage({
|
||||||
|
metadata: { id: "session-1", createdAt: "2026-01-01T00:00:00.000Z" },
|
||||||
|
});
|
||||||
|
const session = createSession(storage);
|
||||||
|
expect(session.getStorage()).toBe(storage);
|
||||||
|
expect(await session.getMetadata()).toEqual({ id: "session-1", createdAt: "2026-01-01T00:00:00.000Z" });
|
||||||
|
});
|
||||||
|
|
||||||
|
it("creates agent harnesses", () => {
|
||||||
|
const session = createSession(new InMemorySessionStorage());
|
||||||
|
const env = new NodeExecutionEnv({ cwd: process.cwd() });
|
||||||
|
const agent = new Agent();
|
||||||
|
const harness = createAgentHarness({ agent, env, session });
|
||||||
|
expect(harness.agent).toBe(agent);
|
||||||
|
expect(harness.conversation.session).toBe(session);
|
||||||
|
});
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user