mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-15 20:03:05 +00:00
12 examples showing increasing levels of customization: - 01-minimal: all defaults - 02-custom-model: model and thinking level - 03-custom-prompt: replace or modify prompt - 04-skills: discover, filter, merge skills - 05-tools: built-in tools, custom tools - 06-hooks: logging, blocking, result modification - 07-context-files: AGENTS.md files - 08-slash-commands: file-based commands - 09-api-keys-and-oauth: API key resolution, OAuth config - 10-settings: compaction, retry, terminal settings - 11-sessions: persistence options - 12-full-control: replace everything Also exports FileSlashCommand type from index.ts
46 lines
1.6 KiB
TypeScript
46 lines
1.6 KiB
TypeScript
/**
|
|
* Session Management
|
|
*
|
|
* Control session persistence: in-memory, new file, continue, or open specific.
|
|
*/
|
|
|
|
import { createAgentSession, SessionManager } from "../../src/index.js";
|
|
|
|
// In-memory (no persistence)
|
|
const { session: inMemory } = await createAgentSession({
|
|
sessionManager: SessionManager.inMemory(),
|
|
});
|
|
console.log("In-memory session:", inMemory.sessionFile ?? "(none)");
|
|
|
|
// New persistent session
|
|
const { session: newSession } = await createAgentSession({
|
|
sessionManager: SessionManager.create(process.cwd()),
|
|
});
|
|
console.log("New session file:", newSession.sessionFile);
|
|
|
|
// Continue most recent session (or create new if none)
|
|
const { session: continued, modelFallbackMessage } = await createAgentSession({
|
|
sessionManager: SessionManager.continueRecent(process.cwd()),
|
|
});
|
|
if (modelFallbackMessage) console.log("Note:", modelFallbackMessage);
|
|
console.log("Continued session:", continued.sessionFile);
|
|
|
|
// List and open specific session
|
|
const sessions = SessionManager.list(process.cwd());
|
|
console.log(`\nFound ${sessions.length} sessions:`);
|
|
for (const info of sessions.slice(0, 3)) {
|
|
console.log(` ${info.id.slice(0, 8)}... - "${info.firstMessage.slice(0, 30)}..."`);
|
|
}
|
|
|
|
if (sessions.length > 0) {
|
|
const { session: opened } = await createAgentSession({
|
|
sessionManager: SessionManager.open(sessions[0].path),
|
|
});
|
|
console.log(`\nOpened: ${opened.sessionId}`);
|
|
}
|
|
|
|
// Custom session directory
|
|
// const { session } = await createAgentSession({
|
|
// agentDir: "/custom/agent",
|
|
// sessionManager: SessionManager.create(process.cwd(), "/custom/agent"),
|
|
// });
|