Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
bentwnghk committed Dec 23, 2024
2 parents 4e01e0e + 4f6d8fc commit b451324
Show file tree
Hide file tree
Showing 10 changed files with 1,516 additions and 7,233 deletions.
8,628 changes: 1,422 additions & 7,206 deletions changelog/v1.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
"dependencies": {
"@ant-design/icons": "^5.5.1",
"@ant-design/pro-components": "^2.7.18",
"@anthropic-ai/sdk": "^0.32.0",
"@anthropic-ai/sdk": "^0.33.0",
"@auth/core": "^0.37.0",
"@aws-sdk/client-bedrock-runtime": "^3.675.0",
"@aws-sdk/client-s3": "^3.675.0",
Expand Down
2 changes: 2 additions & 0 deletions src/const/version.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ export const CURRENT_VERSION = pkg.version;
export const isServerMode = getServerDBConfig().NEXT_PUBLIC_ENABLED_SERVER_SERVICE;
export const isUsePgliteDB = process.env.NEXT_PUBLIC_CLIENT_DB === 'pglite';

export const isDeprecatedEdition = !isServerMode && !isUsePgliteDB;

// @ts-ignore
export const isCustomBranding = BRANDING_NAME !== 'Mr.🆖 AI';
// @ts-ignore
Expand Down
6 changes: 3 additions & 3 deletions src/features/Conversation/hooks/useChatListActionsBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Copy, Edit, ListRestart, RotateCcw, Split, Trash } from 'lucide-react';
import { useMemo } from 'react';
import { useTranslation } from 'react-i18next';

import { isServerMode } from '@/const/version';
import { isDeprecatedEdition } from '@/const/version';

interface ChatListActionsBar {
branching: ActionIconGroupItems;
Expand All @@ -23,10 +23,10 @@ export const useChatListActionsBar = ({
return useMemo(
() => ({
branching: {
disable: !isServerMode,
disable: isDeprecatedEdition,
icon: Split,
key: 'branching',
label: isServerMode
label: !isDeprecatedEdition
? t('branching', { defaultValue: 'Create Sub Topic' })
: t('branchingDisable'),
},
Expand Down
2 changes: 1 addition & 1 deletion src/locales/default/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export default {
blog: 'Mr.🆖 AI Creator',
branching: '创建子话题',
branchingDisable:
'「子话题」功能仅服务端版本可用,如需该功能,请切换到服务端部署模式',
'「子话题」功能在当前模式下不可用,如需该功能,请切换到 Postgres/Pglite DB 模式',
cancel: '取消',
changelog: '取得金钥',
clientDB: {
Expand Down
57 changes: 57 additions & 0 deletions src/services/thread/client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { INBOX_SESSION_ID } from '@/const/session';
import { clientDB } from '@/database/client/db';
import { MessageModel } from '@/database/server/models/message';
import { ThreadModel } from '@/database/server/models/thread';
import { BaseClientService } from '@/services/baseClientService';
import { CreateMessageParams } from '@/types/message';
import { CreateThreadParams, ThreadItem } from '@/types/topic';

import { IThreadService } from './type';

interface CreateThreadWithMessageParams extends CreateThreadParams {
message: CreateMessageParams;
}
export class ClientService extends BaseClientService implements IThreadService {
private get threadModel(): ThreadModel {
return new ThreadModel(clientDB as any, this.userId);
}
private get messageModel(): MessageModel {
return new MessageModel(clientDB as any, this.userId);
}

getThreads = async (topicId: string): Promise<ThreadItem[]> => {
return this.threadModel.queryByTopicId(topicId);
};

createThreadWithMessage = async (
input: CreateThreadWithMessageParams,
): Promise<{ messageId: string; threadId: string }> => {
const thread = await this.threadModel.create({
parentThreadId: input.parentThreadId,
sourceMessageId: input.sourceMessageId,
title: input.message.content.slice(0, 20),
topicId: input.topicId,
type: input.type,
});

const message = await this.messageModel.create({
...input.message,
sessionId: this.toDbSessionId(input.message.sessionId) as string,
threadId: thread?.id,
});

return { messageId: message?.id, threadId: thread?.id };
};

updateThread(id: string, data: Partial<ThreadItem>): Promise<any> {
return this.threadModel.update(id, data);
}

removeThread(id: string): Promise<any> {
return this.threadModel.delete(id);
}

private toDbSessionId(sessionId: string | undefined) {
return sessionId === INBOX_SESSION_ID ? null : sessionId;
}
}
5 changes: 5 additions & 0 deletions src/services/thread/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { ClientService } from './client';
import { ServerService } from './server';

export const threadService =
process.env.NEXT_PUBLIC_SERVICE_MODE === 'server' ? new ServerService() : new ClientService();
23 changes: 3 additions & 20 deletions src/services/thread.ts → src/services/thread/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ import { lambdaClient } from '@/libs/trpc/client';
import { CreateMessageParams } from '@/types/message';
import { CreateThreadParams, ThreadItem } from '@/types/topic';

import { IThreadService } from './type';

interface CreateThreadWithMessageParams extends CreateThreadParams {
message: CreateMessageParams;
}
export class ThreadService {
export class ServerService implements IThreadService {
getThreads = (topicId: string): Promise<ThreadItem[]> => {
return lambdaClient.thread.getThreads.query({ topicId });
};
Expand All @@ -21,34 +23,15 @@ export class ThreadService {
});
}

// createThread(params: CreateThreadParams): Promise<string> {
// return lambdaClient.thread.createThread.mutate(params);
// }

updateThread(id: string, data: Partial<ThreadItem>): Promise<any> {
return lambdaClient.thread.updateThread.mutate({ id, value: data });
}

//
removeThread(id: string): Promise<any> {
return lambdaClient.thread.removeThread.mutate({ id });
}
//
// removeThreads(sessionId: string): Promise<any> {
// return lambdaClient.thread.batchDeleteBySessionId.mutate({ id: this.toDbSessionId(sessionId) });
// }
//
// batchRemoveThreads(topics: string[]): Promise<any> {
// return lambdaClient.thread.batchDelete.mutate({ ids: topics });
// }
//
// removeAllThread(): Promise<any> {
// return lambdaClient.thread.removeAllThreads.mutate();
// }

private toDbSessionId(sessionId: string | undefined) {
return sessionId === INBOX_SESSION_ID ? null : sessionId;
}
}

export const threadService = new ThreadService();
20 changes: 20 additions & 0 deletions src/services/thread/type.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/* eslint-disable typescript-sort-keys/interface */
import { CreateMessageParams } from '@/types/message';
import { CreateThreadParams, ThreadItem } from '@/types/topic';

interface CreateThreadWithMessageParams extends CreateThreadParams {
message: CreateMessageParams;
}

export interface IThreadService {
getThreads(topicId: string): Promise<ThreadItem[]>;

createThreadWithMessage({
message,
...params
}: CreateThreadWithMessageParams): Promise<{ messageId: string; threadId: string }>;

updateThread(id: string, data: Partial<ThreadItem>): Promise<any>;
//
removeThread(id: string): Promise<any>;
}
4 changes: 2 additions & 2 deletions src/store/chat/slices/thread/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { StateCreator } from 'zustand/vanilla';

import { chainSummaryTitle } from '@/chains/summaryTitle';
import { LOADING_FLAT, THREAD_DRAFT_ID } from '@/const/message';
import { isServerMode } from '@/const/version';
import { isDeprecatedEdition } from '@/const/version';
import { useClientDataSWR } from '@/libs/swr';
import { chatService } from '@/services/chat';
import { threadService } from '@/services/thread';
Expand Down Expand Up @@ -211,7 +211,7 @@ export const chatThreadMessage: StateCreator<

useFetchThreads: (enable, topicId) =>
useClientDataSWR<ThreadItem[]>(
enable && !!topicId && isServerMode ? [SWR_USE_FETCH_THREADS, topicId] : null,
enable && !!topicId && !isDeprecatedEdition ? [SWR_USE_FETCH_THREADS, topicId] : null,
async ([, topicId]: [string, string]) => threadService.getThreads(topicId),
{
suspense: true,
Expand Down

0 comments on commit b451324

Please sign in to comment.