feat: setup barrelsby for automatic barrel file generation

Add barrelsby as a dev dependency with a `generate-barrels` npm script and a `barrelesby.json` config targeting `./src`. This automates creation of barrel/index files to simplify imports across the project.
This commit is contained in:
2026-06-08 13:07:37 +08:00
parent 14d6e7c41e
commit c22b90c7f4
41 changed files with 2165 additions and 1 deletions
@@ -0,0 +1,60 @@
/**
* 聊天历史响应
* 原始 Dart: ChatHistoryResponse (lib/data/models/chat/chat_response.dart)
*
* 注:原始 Dart 中 `total` 为 `int?`,按"全部非空"约定兜底为 0。
*/
import { ChatMessage } from "./chat_message";
export class ChatHistoryResponse {
readonly messages: ChatMessage[];
readonly total: number;
readonly limit: number;
readonly offset: number;
constructor(params: {
messages: ChatMessage[];
total?: number;
limit: number;
offset: number;
}) {
this.messages = params.messages;
this.total = params.total ?? 0;
this.limit = params.limit;
this.offset = params.offset;
Object.freeze(this);
}
toJson(): Record<string, unknown> {
return {
messages: this.messages.map((m) => m.toJson()),
total: this.total,
limit: this.limit,
offset: this.offset,
};
}
static fromJson(json: Record<string, unknown>): ChatHistoryResponse {
const requireNumber = (key: string): number => {
const v = json[key];
if (typeof v !== "number") {
throw new Error(
`ChatHistoryResponse.${key} is required and must be a number`
);
}
return v;
};
const rawMessages = json.messages;
const messages: ChatMessage[] = Array.isArray(rawMessages)
? (rawMessages as Record<string, unknown>[]).map((m) =>
ChatMessage.fromJson(m)
)
: [];
return new ChatHistoryResponse({
messages,
total: typeof json.total === "number" ? json.total : undefined,
limit: requireNumber("limit"),
offset: requireNumber("offset"),
});
}
}