
Research
/Security News
Laravel Lang Compromised with RCE Backdoor Across 700+ Versions
Laravel Lang packages were compromised with an RCE backdoor across hundreds of versions, exposing cloud, CI/CD, and developer secrets.
@stackone/openai-agents-js-sessions
Advanced tools
Session memory module for managing conversation history across multiple OpenAI agent runs
In-memory and SQLite, PostgreSQL, and MySQL with Drizzle ORM sessions for maintaining conversation history with OpenAI Agents JS SDK. This package is based on the OpenAI Agents Python SDK Sessions.
npm install @stackone/openai-agents-js-sessions
For database support, install the appropriate driver:
# SQLite
npm install drizzle-orm better-sqlite3
# PostgreSQL
npm install drizzle-orm pg
# MySQL
npm install drizzle-orm mysql2
In-memory storage (data lost when process ends). Ideal for development and testing.
import { InMemorySession } from '@stackone/openai-agents-js-sessions';
const session = new InMemorySession('chat_123');
Drizzle ORM-powered storage supporting SQLite, PostgreSQL, and MySQL. Matches the Python SDK's SQLAlchemySession implementation with two tables:
agent_sessions - Tracks session metadata (created_at, updated_at)agent_messages - Stores conversation messages with timestampsimport { DrizzleSession } from '@stackone/openai-agents-js-sessions';
// SQLite
const session = await DrizzleSession.fromUrl('chat_123', 'sqlite:./sessions.db');
// PostgreSQL
const session = await DrizzleSession.fromUrl('chat_123', 'postgres://user:pass@localhost:5432/mydb');
// MySQL
const session = await DrizzleSession.fromUrl('chat_123', 'mysql://user:pass@localhost:3306/mydb');
// With custom configuration
const session = await DrizzleSession.fromUrl('chat_123', 'postgres://localhost/db', {
createTables: true, // Auto-create tables (default: true)
maxRetries: 6, // Maximum connection retry attempts (default: 3)
retryDelay: 2000, // Delay between retries in ms (default: 1000)
connectionTimeout: 20000, // Connection timeout in ms (default: 10000)
});
For secure PostgreSQL connections (e.g., AWS RDS, Azure Database for PostgreSQL), you can configure SSL/TLS:
import { DrizzleSession } from '@stackone/openai-agents-js-sessions';
import fs from 'node:fs';
// Basic SSL (encrypted connection, no certificate verification)
const session = await DrizzleSession.fromUrl(
'chat_123',
'postgres://user:pass@host:5432/db',
{
ssl: true
}
);
// SSL with certificate verification (recommended for production)
const session = await DrizzleSession.fromUrl(
'chat_123',
'postgres://user:pass@rds-endpoint.amazonaws.com:5432/mydb',
{
ssl: {
rejectUnauthorized: true,
ca: fs.readFileSync('./rds-ca.pem', 'utf8'),
}
}
);
// SSL with client certificates (mutual TLS)
const session = await DrizzleSession.fromUrl(
'chat_123',
'postgres://user:pass@host:5432/db',
{
ssl: {
rejectUnauthorized: true,
ca: fs.readFileSync('./ca-cert.pem', 'utf8'),
cert: fs.readFileSync('./client-cert.pem', 'utf8'),
key: fs.readFileSync('./client-key.pem', 'utf8'),
}
}
);
For AWS RDS PostgreSQL, download the certificate bundle from AWS Documentation:
import { DrizzleSession } from '@stackone/openai-agents-js-sessions';
import fs from 'node:fs';
const session = await DrizzleSession.fromUrl(
'chat_123',
`postgres://${username}:${password}@${rdsEndpoint}:5432/${database}`,
{
ssl: {
rejectUnauthorized: true,
ca: fs.readFileSync('./rds-ca-2019-root.pem', 'utf8'),
}
}
);
SSL Configuration Options:
ssl: true - Enable SSL without certificate verification (encrypted but less secure)ssl: { ... } - Configure SSL with certificate verification:
rejectUnauthorized - Verify server certificate (default: true, recommended)ca - Certificate Authority certificate(s)cert - Client certificate for mutual TLS (optional)key - Client private key for mutual TLS (optional)import { Agent, run, user, type AgentInputItem } from '@openai/agents';
import { InMemorySession } from '@stackone/openai-agents-js-sessions';
// Create your agent
const agent = new Agent({
name: 'Customer Support',
instructions: 'You are a helpful customer support assistant.',
model: 'gpt-5.1',
});
// Create a session
const sessionId = 'chat_123';
const session = new InMemorySession(sessionId);
// First conversation turn
async function handleUserMessage(userMessage: string) {
// Load existing conversation history
const history = await session.getItems();
// Add the new user message
const newUserMessage = user(userMessage);
const input: AgentInputItem[] = [...history, newUserMessage];
// Run the agent with full conversation context
const result = await run(agent, input);
await result.completed;
// Save the conversation (user message + agent response) to session
const newItems = result.history.slice(history.length);
await session.addItems([newUserMessage, ...newItems]);
return result;
}
// Example conversation
await handleUserMessage('Hi, I need help with my order');
await handleUserMessage('It was order #12345'); // Agent remembers previous context
await handleUserMessage('Can you check the status?'); // Agent still has full context
All session implementations provide the following methods:
getItems(limit?: number): Promise<AgentInputItem[]>Retrieve the conversation history for this session.
limit - Maximum number of items to retrieve. If undefined, retrieves all items.addItems(items: AgentInputItem[]): Promise<void>Add new items to the conversation history.
popItem(): Promise<AgentInputItem | undefined>Remove and return the most recent item from the session.
clearSession(): Promise<void>Clear all items for this session.
static fromUrl(sessionId: string, url: string, config?: ConnectionConfig): Promise<DrizzleSession>Create a new database-backed session.
sessionId - Unique identifier for this sessionurl - Database connection URL:
sqlite::memory: or sqlite:./path/to/db.sqlitepostgres://user:pass@host:port/databasemysql://user:pass@host:port/databaseconfig - Optional connection configuration:
createTables - Auto-create tables if they don't exist (default: true)maxRetries - Maximum connection retry attempts (default: 3)retryDelay - Delay between retries in milliseconds (default: 1000)connectionTimeout - Connection timeout in milliseconds (default: 10000)ssl - PostgreSQL SSL configuration (boolean or object):
true - Enable SSL without certificate verificationrejectUnauthorized, ca, cert, key - Configure SSL with certificate verificationclose(): Promise<void>Close the database connection and release resources (this is handled automatically).
# Install dependencies
npm install
# Build
npm run build
# Run tests
npm test
# Run tests with coverage
npm run test:coverage
# Lint
npm run lint
# Fix linting issues
npm run lint:fix
Contributions are welcome! Please follow the Conventional Commits specification for commit messages.
MIT © StackOne
FAQs
Session memory module for managing conversation history across multiple OpenAI agent runs
We found that @stackone/openai-agents-js-sessions demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Research
/Security News
Laravel Lang packages were compromised with an RCE backdoor across hundreds of versions, exposing cloud, CI/CD, and developer secrets.

Security News
Socket found a malicious postinstall hook across 700+ GitHub repos, including PHP packages on Packagist and Node.js project repositories.

Security News
Vibe coding at scale is reshaping how packages are created, contributed, and selected across the software supply chain