From 9a0515d8d0a5734d107b47cbb92730f2d747eae5 Mon Sep 17 00:00:00 2001 From: sunshinesmilelk <1176136681@qq.com> Date: Fri, 7 Feb 2025 23:07:16 +0800 Subject: [PATCH] fix: fix ai-native package --- .../src/ai-native-code-block.tsx | 138 +++++++++--------- packages/libro-ai-native/src/module.ts | 28 ++-- 2 files changed, 83 insertions(+), 83 deletions(-) diff --git a/packages/libro-ai-native/src/ai-native-code-block.tsx b/packages/libro-ai-native/src/ai-native-code-block.tsx index eb96b8be..487296c1 100644 --- a/packages/libro-ai-native/src/ai-native-code-block.tsx +++ b/packages/libro-ai-native/src/ai-native-code-block.tsx @@ -62,77 +62,77 @@ export const CodeBlockInCell = (props: any) => { return {children}; }; -// export const CodeBlockInChat = (props: any) => { -// const { className, children } = props; -// const instance = useInject(ViewInstance); -// const cell = instance.libro?.activeCell; +export const CodeBlockInChat = (props: any) => { + const { className, children } = props; + const instance = useInject(ViewInstance); + const cell = instance.libro?.activeCell; -// const insertCell = async (data: any) => { -// const libro = instance.libro; -// if (!libro) { -// return; -// } -// const insertIndex = libro.model.cells.findIndex( -// (c) => c.id === libro.activeCell?.id, -// ); -// await libro.addCell( -// { -// id: v4(), -// cell: { cell_type: 'code', source: data, metadata: {} }, -// }, -// insertIndex + 1, -// ); -// }; + const insertCell = async (data: any) => { + const libro = instance.libro; + if (!libro) { + return; + } + const insertIndex = libro.model.cells.findIndex( + (c) => c.id === libro.activeCell?.id, + ); + await libro.addCell( + { + id: v4(), + cell: { cell_type: 'code', source: data, metadata: {} }, + }, + insertIndex + 1, + ); + }; -// const replace = (data: any) => { -// if (cell instanceof LibroCodeCellView && cell.editor) { -// const length = cell.editor.model.value.length; -// const start = cell.editor.getPositionAt(0); -// const end = cell.editor.getPositionAt(length); -// if (start && end) { -// cell.editor.replaceSelection(data, { -// start, -// end, -// }); -// } -// } -// }; + const replace = (data: any) => { + if (cell instanceof LibroCodeCellView && cell.editor) { + const length = cell.editor.model.value.length; + const start = cell.editor.getPositionAt(0); + const end = cell.editor.getPositionAt(length); + if (start && end) { + cell.editor.replaceSelection(data, { + start, + end, + }); + } + } + }; -// if (!props.inline && className) { -// const [, lang] = /language-(\w+)/.exec(className || '') || []; + if (!props.inline && className) { + const [, lang] = /language-(\w+)/.exec(className || '') || []; -// return ( -//
-//         {lang && 
{lang}
} -// { -// copy(children); -// message.success(l10n.t('代码已复制')); -// }} -// className={`chat-msg-md-code-copy`} -// /> -// -// {typeof children === 'string' ? children.trim() : children} -// -//
-// -// -//
-//
-// ); -// } + return ( +
+        {lang && 
{lang}
} + { + copy(children); + message.success(l10n.t('代码已复制')); + }} + className={`chat-msg-md-code-copy`} + /> + + {typeof children === 'string' ? children.trim() : children} + +
+ + +
+
+ ); + } -// return {children}; -// }; + return {children}; +}; diff --git a/packages/libro-ai-native/src/module.ts b/packages/libro-ai-native/src/module.ts index 6f2db6cd..480a733c 100644 --- a/packages/libro-ai-native/src/module.ts +++ b/packages/libro-ai-native/src/module.ts @@ -1,8 +1,8 @@ import { CodeEditorModule } from '@difizen/libro-code-editor'; import { ManaModule } from '@difizen/libro-common/app'; import { CellOutputTopProvider, ErrorOutputModel } from '@difizen/libro-jupyter'; -// import { ChatView } from '@difizen/magent-chat'; -// import { LibroChatModule, LibroChatService } from '@difizen/magent-libro'; +import { ChatView } from '@difizen/magent-chat'; +import { LibroChatModule, LibroChatService } from '@difizen/magent-libro'; import { LibroAICompletionModule } from './ai-inline-completions/module.js'; import { LibroAINativeCommandContribution } from './ai-native-command-contribution.js'; @@ -13,8 +13,8 @@ import { LibroAIChatSlotContribution } from './chat-slot-contribution.js'; import { LibroChatView } from './chat-view.js'; import { AIErrorOutputModel } from './error-output-model.js'; import { LibroAIChatMessageItemModel } from './libro-ai-msg-item-model.js'; -// import { LibroAINativeChatService } from './libro-ai-native-chat-service.js'; -// import { LibroAiNativeChatView } from './libro-ai-native-chat-view.js'; +import { LibroAINativeChatService } from './libro-ai-native-chat-service.js'; +import { LibroAiNativeChatView } from './libro-ai-native-chat-view.js'; import { LibroAINativeColorRegistry } from './libro-ai-native-color-registry.js'; export const LibroAINativeModuleSetting = { @@ -29,23 +29,23 @@ export const LibroAINativeModule = ManaModule.create() LibroAINativeCommandContribution, LibroAINativeService, LibroAIChatMessageItemModel, - // LibroAINativeForCellView, + LibroAINativeForCellView, { token: ErrorOutputModel, useClass: AIErrorOutputModel, }, - // { - // token: ChatView, - // useClass: LibroAiNativeChatView, - // }, - // { - // token: LibroChatService, - // useClass: LibroAINativeChatService, - // }, + { + token: ChatView, + useClass: LibroAiNativeChatView, + }, + { + token: LibroChatService, + useClass: LibroAINativeChatService, + }, { token: CellOutputTopProvider, useValue: LibroAINativeCellTopBlank, }, ) .canload(() => Promise.resolve(LibroAINativeModuleSetting.loadable)) - .dependOn(CodeEditorModule, LibroAICompletionModule); + .dependOn(LibroChatModule, CodeEditorModule, LibroAICompletionModule);