mirror of
https://github.com/harivansh-afk/sandbox-agent.git
synced 2026-04-15 09:01:17 +00:00
feat: add session persistence examples and SQLite driver
This commit is contained in:
parent
64d1324628
commit
3c2a9cbbbb
14 changed files with 524 additions and 11 deletions
39
examples/persist-sqlite/src/index.ts
Normal file
39
examples/persist-sqlite/src/index.ts
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
import { SandboxAgent } from "sandbox-agent";
|
||||
import { SQLiteSessionPersistDriver } from "@sandbox-agent/persist-sqlite";
|
||||
import { startDockerSandbox } from "@sandbox-agent/example-shared/docker";
|
||||
import { detectAgent } from "@sandbox-agent/example-shared";
|
||||
|
||||
const persist = new SQLiteSessionPersistDriver({ filename: "./sessions.db" });
|
||||
|
||||
console.log("Starting sandbox...");
|
||||
const sandbox = await startDockerSandbox({
|
||||
port: 3000,
|
||||
setupCommands: [
|
||||
"sandbox-agent install-agent claude",
|
||||
"sandbox-agent install-agent codex",
|
||||
],
|
||||
});
|
||||
|
||||
const sdk = await SandboxAgent.connect({ baseUrl: sandbox.baseUrl, persist });
|
||||
|
||||
const session = await sdk.createSession({ agent: detectAgent() });
|
||||
console.log(`Created session ${session.id}`);
|
||||
|
||||
await session.prompt([{ type: "text", text: "Say hello in one sentence." }]);
|
||||
console.log("Prompt complete.");
|
||||
|
||||
const sessions = await sdk.listSessions();
|
||||
console.log(`\nSessions (${sessions.items.length}):`);
|
||||
for (const s of sessions.items) {
|
||||
console.log(` ${s.id} agent=${s.agent}`);
|
||||
}
|
||||
|
||||
const events = await sdk.getEvents({ sessionId: session.id });
|
||||
console.log(`\nSession history (${events.items.length} events):`);
|
||||
for (const e of events.items) {
|
||||
console.log(` [${e.eventIndex}] ${e.sender}: ${JSON.stringify(e.payload).slice(0, 120)}`);
|
||||
}
|
||||
|
||||
persist.close();
|
||||
await sdk.dispose();
|
||||
await sandbox.cleanup();
|
||||
Loading…
Add table
Add a link
Reference in a new issue