Skip to content

Commit

Permalink
♻️ chore: add init client db code (#5127)
Browse files Browse the repository at this point in the history
  • Loading branch information
arvinxx authored Dec 22, 2024
1 parent 5677e89 commit dba432f
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 28 deletions.
2 changes: 1 addition & 1 deletion src/services/session/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ export class ClientService implements ISessionService {
}

async updateSessionGroup(id: string, data: Partial<SessionGroupItem>) {
return SessionGroupModel.update(id, data);
return SessionGroupModel.update(id, data as any);
}

async updateSessionGroupOrder(sortMap: { id: string; sort: number }[]) {
Expand Down
7 changes: 3 additions & 4 deletions src/store/chat/slices/builtinTool/action.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,9 @@ describe('chatToolSlice', () => {
url: '',
});
vi.spyOn(result.current, 'toggleDallEImageLoading');
vi.spyOn(ClientService.prototype, 'checkFileHash').mockImplementation(async () => ({
isExist: false,
metadata: {},
}));
vi.spyOn(ClientService.prototype, 'checkFileHash').mockImplementation(
async () => ({ isExist: false }) as any,
);

await act(async () => {
await result.current.generateImageFromPrompts(prompts, messageId);
Expand Down
12 changes: 6 additions & 6 deletions src/store/session/slices/sessionGroup/reducer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ describe('sessionGroupsReducer', () => {
{
id: nanoid(),
name: 'Group 1',
createdAt: Date.now(),
updatedAt: Date.now(),
createdAt: new Date(),
updatedAt: new Date(),
},
{
id: nanoid(),
name: 'Group 2',
createdAt: Date.now(),
updatedAt: Date.now(),
createdAt: new Date(),
updatedAt: new Date(),
sort: 1,
},
];
Expand All @@ -26,8 +26,8 @@ describe('sessionGroupsReducer', () => {
const newItem: SessionGroupItem = {
id: nanoid(),
name: 'New Group',
createdAt: Date.now(),
updatedAt: Date.now(),
createdAt: new Date(),
updatedAt: new Date(),
};

const result = sessionGroupsReducer(initialState, {
Expand Down
29 changes: 29 additions & 0 deletions src/types/clientDB.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// 定义加载状态类型
export enum DatabaseLoadingState {
Error = 'error',
Finished = 'finished',
Idle = 'idle',
Initializing = 'initializing',
LoadingDependencies = 'loadingDependencies',
LoadingWasm = 'loadingWasm',
Migrating = 'migrating',
Ready = 'ready',
}

export const ClientDatabaseInitStages = [
DatabaseLoadingState.Idle,
DatabaseLoadingState.Initializing,
DatabaseLoadingState.LoadingDependencies,
DatabaseLoadingState.LoadingWasm,
DatabaseLoadingState.Migrating,
DatabaseLoadingState.Finished,
];

// 定义进度回调接口
export interface ClientDBLoadingProgress {
costTime?: number;
phase: 'wasm' | 'dependencies';
progress: number;
}

export type OnStageChange = (state: DatabaseLoadingState) => void;
22 changes: 17 additions & 5 deletions src/types/importer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ import {
} from '@/types/message';
import { MetaData } from '@/types/meta';
import { SessionGroupId } from '@/types/session';
import { ChatTopic } from '@/types/topic';

interface ImportSession {
export interface ImportSession {
config: LobeAgentConfig;
createdAt: string;
group?: SessionGroupId;
Expand All @@ -22,7 +21,7 @@ interface ImportSession {
updatedAt: string;
}

interface ImportMessage {
export interface ImportMessage {
content: string;
createdAt: number;
error?: ChatMessageError;
Expand Down Expand Up @@ -64,19 +63,32 @@ interface ImportMessage {
updatedAt: number;
}

interface ImportSessionGroup {
export interface ImportSessionGroup {
createdAt: number;
id: string;
name: string;
sort?: number | null;
updatedAt: number;
}
export interface ImportTopic {
createdAt: number;
favorite?: boolean;
historySummary?: string;
id: string;
metadata?: {
model?: string;
provider?: string;
};
sessionId?: string;
title: string;
updatedAt: number;
}

export interface ImporterEntryData {
messages?: ImportMessage[];
sessionGroups?: ImportSessionGroup[];
sessions?: ImportSession[];
topics?: ChatTopic[];
topics?: ImportTopic[];
version: number;
}

Expand Down
9 changes: 0 additions & 9 deletions src/types/meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,10 @@ export const LobeMetaDataSchema = z.object({
export type MetaData = z.infer<typeof LobeMetaDataSchema>;

export interface BaseDataModel {
/**
* @deprecated
*/
createAt?: number;

createdAt: number;

id: string;
meta: MetaData;

/**
* @deprecated
*/
updateAt?: number;
updatedAt: number;
}
6 changes: 3 additions & 3 deletions src/types/session/sessionGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ export enum SessionDefaultGroup {
export type SessionGroupId = SessionDefaultGroup | string;

export interface SessionGroupItem {
createdAt: number;
createdAt: Date;
id: string;
name: string;
sort?: number;
updatedAt: number;
sort?: number | null;
updatedAt: Date;
}

export type SessionGroups = SessionGroupItem[];
Expand Down

0 comments on commit dba432f

Please sign in to comment.