refactor(storage): 采用 OpenCode 风格三层存储结构
重构消息存储系统,从"每条消息一个文件"改为分层存储:
- Session → Message → Parts 三层结构
- 12 种 Part 类型(TextPart, ToolPart, ReasoningPart 等)
- ToolPart 状态机(pending → running → completed/error)
- 通用 Storage API(read/write/list/remove)
新增文件:
- parts.ts: Part 类型定义(Zod schema)
- message.ts: MessageInfo 类型定义
- id.ts: ID 生成器
- storage/: 分层存储实现
删除旧文件:
- storage.ts, types.ts, migration.ts
存储路径:
~/.local/share/ai-assist/
├── session/{projectId}/{sessionId}.json
├── message/{sessionId}/{messageId}.json
├── part/{messageId}/{partId}.json
└── todo/{sessionId}.json
This commit is contained in:
@@ -1,6 +1,28 @@
|
||||
import type { Todo, TodoStatus } from '../../session/types.js';
|
||||
import type { TodoItem } from '../../session/storage/todo.js';
|
||||
import type { SessionManager } from '../../session/index.js';
|
||||
|
||||
// 兼容旧接口的 Todo 类型
|
||||
export type Todo = {
|
||||
id: string;
|
||||
content: string;
|
||||
status: 'pending' | 'in_progress' | 'completed';
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
};
|
||||
|
||||
export type TodoStatus = 'pending' | 'in_progress' | 'completed';
|
||||
|
||||
// 将 TodoItem 转换为 Todo
|
||||
function toTodo(item: TodoItem): Todo {
|
||||
return {
|
||||
id: item.id,
|
||||
content: item.content,
|
||||
status: item.status,
|
||||
createdAt: new Date(item.createdAt).toISOString(),
|
||||
updatedAt: new Date(item.updatedAt).toISOString(),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Todo 管理器
|
||||
* 提供对当前会话 todo 列表的操作接口
|
||||
@@ -22,7 +44,7 @@ class TodoManager {
|
||||
if (!this.sessionManager) {
|
||||
return [];
|
||||
}
|
||||
return this.sessionManager.getTodos();
|
||||
return this.sessionManager.getTodos().map(toTodo);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { ToolResult } from '../../types/index.js';
|
||||
import type { ToolWithMetadata } from '../types.js';
|
||||
import type { Todo, TodoStatus } from '../../session/types.js';
|
||||
import type { Todo, TodoStatus } from './todo-manager.js';
|
||||
import { todoManager } from './todo-manager.js';
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user