
Company News
Free Business Plan Upgrades for Open Source Maintainers
Open source maintainers are under more pressure than ever. We're raising our open source program from the Team plan to the Business plan, free.
@deepracticex/conversation-storage
Advanced tools
DeeChat 对话存储管理包 - 纯存储层实现
ConversationDomain (业务层)
↓ 依赖注入
conversation-storage (存储层)
↓ 持久化
SQLite 数据库
interface ConversationSession {
id: string // 会话ID
title: string // 会话标题
ai_config_name: string // 关联的AI配置名称
created_at: string // 创建时间
updated_at: string // 更新时间
message_count: number // 消息数量
}
interface ConversationMessage {
id: string // 消息ID
session_id: string // 所属会话ID
role: 'user' | 'assistant' | 'system' // 角色
content: string // 消息内容
timestamp: string // 时间戳
token_usage?: TokenUsage // Token使用情况(可选)
}
createSession(data: CreateSessionData): Promise<ConversationSession>getSession(sessionId: string): Promise<ConversationSession | null>getSessions(): Promise<ConversationSession[]>updateSession(sessionId: string, updates: Partial<SessionData>): Promise<void>deleteSession(sessionId: string): Promise<void>saveMessage(data: CreateMessageData): Promise<ConversationMessage>getMessageHistory(sessionId: string): Promise<ConversationMessage[]>deleteMessagesBySession(sessionId: string): Promise<void>updateMessageCount(sessionId: string): Promise<void>CREATE TABLE sessions (
id TEXT PRIMARY KEY,
title TEXT NOT NULL,
ai_config_name TEXT NOT NULL,
created_at TEXT NOT NULL,
updated_at TEXT NOT NULL,
message_count INTEGER DEFAULT 0
);
CREATE TABLE messages (
id TEXT PRIMARY KEY,
session_id TEXT NOT NULL,
role TEXT NOT NULL CHECK(role IN ('user', 'assistant', 'system')),
content TEXT NOT NULL,
timestamp TEXT NOT NULL,
token_usage TEXT, -- JSON格式存储
FOREIGN KEY (session_id) REFERENCES sessions(id) ON DELETE CASCADE
);
CREATE INDEX idx_messages_session_id ON messages(session_id);
CREATE INDEX idx_messages_timestamp ON messages(timestamp);
CREATE INDEX idx_sessions_updated_at ON sessions(updated_at);
export class ConversationDomain implements IDomain {
private conversationStorage: ConversationStorage
constructor(
private aiConfigDomain: AIConfigurationDomain,
conversationStorage: ConversationStorage
) {
this.conversationStorage = conversationStorage
}
async createSession(input: CreateSessionInput): Promise<ConversationSession> {
// 业务逻辑验证
const aiConfig = await this.aiConfigDomain.getUserConfiguration(input.ai_config_name)
if (!aiConfig) {
throw new Error(`AI配置 '${input.ai_config_name}' 不存在`)
}
// 调用存储层
return await this.conversationStorage.createSession({
title: input.title || `对话 ${new Date().toLocaleString()}`,
ai_config_name: input.ai_config_name
})
}
}
参照 @deepracticex/ai-config 包的设计模式:
FAQs
DeeChat 对话存储管理包 - 纯存储层实现,支持统一数据库文件的表管理模式
The npm package @deepracticex/conversation-storage receives a total of 2 weekly downloads. As such, @deepracticex/conversation-storage popularity was classified as not popular.
We found that @deepracticex/conversation-storage demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 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.

Company News
Open source maintainers are under more pressure than ever. We're raising our open source program from the Team plan to the Business plan, free.

Security News
The supply chain control that delays freshly published gems now covers lockfile generation and gem vendoring in Ruby projects.

Security News
During a UK cyber test, a Mythos 5 agent used sockpuppets, social engineering, and prompt injection to try to get a maintainer to merge malware.