Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/v3.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
bytemain committed Sep 6, 2024
2 parents 86c0b94 + 66b0b56 commit 5ccece9
Show file tree
Hide file tree
Showing 97 changed files with 831 additions and 387 deletions.
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"$schema": "node_modules/lerna/schemas/lerna-schema.json",
"version": "3.3.0"
"version": "3.3.1"
}
2 changes: 1 addition & 1 deletion packages/addons/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@opensumi/ide-addons",
"version": "3.3.0",
"version": "3.3.1",
"files": [
"lib",
"src"
Expand Down
2 changes: 1 addition & 1 deletion packages/ai-native/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@opensumi/ide-ai-native",
"version": "3.3.0",
"version": "3.3.1",
"files": [
"lib",
"src"
Expand Down
4 changes: 2 additions & 2 deletions packages/ai-native/src/browser/ai-core.contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -341,8 +341,8 @@ export class AINativeBrowserContribution
});

commands.registerCommand(AI_INLINE_COMPLETION_REPORTER, {
execute: (relationId: string, sessionId: string, accept: boolean) => {
this.aiCompletionsService.report({ sessionId, accept, relationId });
execute: (relationId: string, sessionId: string, accept: boolean, code: string) => {
this.aiCompletionsService.report({ sessionId, accept, relationId, code });
},
});

Expand Down
1 change: 1 addition & 0 deletions packages/ai-native/src/browser/chat/chat-proxy.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ export class ChatProxyService extends Disposable {
this.aiReporter.end(request.sessionId + '_' + request.requestId, {
message: error.message,
success: false,
command,
});
},
});
Expand Down
38 changes: 32 additions & 6 deletions packages/ai-native/src/browser/chat/chat.view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { Popover, PopoverPosition } from '@opensumi/ide-core-browser/lib/compone
import { EnhanceIcon } from '@opensumi/ide-core-browser/lib/components/ai-native';
import {
AISerivceType,
ActionSourceEnum,
ActionTypeEnum,
ChatFeatureRegistryToken,
ChatRenderRegistryToken,
ChatServiceToken,
Expand Down Expand Up @@ -197,7 +199,9 @@ export const AIChatView = observer(() => {
message: chunk,
});

let renderContent = <ChatMarkdown markdown={chunk} fillInIncompleteTokens />;
let renderContent = (
<ChatMarkdown markdown={chunk} fillInIncompleteTokens agentId={agentId} command={command} />
);

if (chatRenderRegistry.chatAIRoleRender) {
const ChatAIRoleRender = chatRenderRegistry.chatAIRoleRender;
Expand Down Expand Up @@ -322,8 +326,10 @@ export const AIChatView = observer(() => {
relationId: string;
requestId: string;
startTime: number;
command?: string;
agentId?: string;
}) => {
const { userMessage, relationId, requestId, render, startTime } = value;
const { userMessage, relationId, requestId, render, startTime, command, agentId } = value;

msgHistoryManager.addAssistantMessage({
type: 'component',
Expand All @@ -341,6 +347,8 @@ export const AIChatView = observer(() => {
relationId={relationId}
requestId={requestId}
renderContent={render}
command={command}
agentId={agentId}
/>
),
});
Expand All @@ -352,7 +360,8 @@ export const AIChatView = observer(() => {

const handleAgentReply = React.useCallback(
async (value: IChatMessageStructure) => {
const { message, agentId, command } = value;
const { message, agentId, command, reportExtra } = value;
const { actionType, actionSource } = reportExtra || {};

const request = aiChatService.createRequest(message, agentId!, command);
if (!request) {
Expand All @@ -369,7 +378,10 @@ export const AIChatView = observer(() => {
const relationId = aiReporter.start(command || reportType, {
message,
agentId,
command,
userMessage: message,
actionType,
actionSource,
});

msgHistoryManager.addUserMessage({
Expand Down Expand Up @@ -405,6 +417,8 @@ export const AIChatView = observer(() => {
relationId,
requestId: request.requestId,
startTime,
agentId,
command,
});
}
}
Expand All @@ -418,6 +432,8 @@ export const AIChatView = observer(() => {
relationId={relationId}
request={request}
startTime={startTime}
agentId={visibleAgentId}
command={command}
onDidChange={() => {
scrollToBottom();
}}
Expand All @@ -438,10 +454,10 @@ export const AIChatView = observer(() => {
);

const handleSend = React.useCallback(async (value: IChatMessageStructure) => {
const { message, command } = value;
const { message, command, reportExtra } = value;

const agentId = value.agentId ? value.agentId : ChatProxyService.AGENT_ID;
return handleAgentReply({ message, agentId, command });
return handleAgentReply({ message, agentId, command, reportExtra });
}, []);

const handleClear = React.useCallback(() => {
Expand Down Expand Up @@ -531,7 +547,17 @@ export const AIChatView = observer(() => {
<div className={styles.header_operate_right}></div>
</div>
<ChatInputWrapperRender
onSend={(value, agentId, command) => handleSend({ message: value, agentId, command })}
onSend={(value, agentId, command) =>
handleSend({
message: value,
agentId,
command,
reportExtra: {
actionSource: ActionSourceEnum.Chat,
actionType: ActionTypeEnum.Send,
},
})
}
disabled={loading}
enableOptions={true}
theme={theme}
Expand Down
57 changes: 50 additions & 7 deletions packages/ai-native/src/browser/components/ChatEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,14 @@ import Highlight from 'react-highlight';
import { IClipboardService, getIcon, useInjectable, uuid } from '@opensumi/ide-core-browser';
import { Popover } from '@opensumi/ide-core-browser/lib/components';
import { EnhanceIcon } from '@opensumi/ide-core-browser/lib/components/ai-native';
import { ChatFeatureRegistryToken, IAIReporter, localize, runWhenIdle } from '@opensumi/ide-core-common';
import {
ActionSourceEnum,
ActionTypeEnum,
ChatFeatureRegistryToken,
IAIReporter,
localize,
runWhenIdle,
} from '@opensumi/ide-core-common';
import { insertSnippetWithMonacoEditor } from '@opensumi/ide-editor/lib/browser/editor-collection.service';
import { MonacoCommandRegistry } from '@opensumi/ide-editor/lib/browser/monaco-contrib/command/command.service';
import { ITheme, IThemeService } from '@opensumi/ide-theme';
Expand All @@ -18,7 +25,15 @@ import { highLightLanguageSupport } from './highLight';

import './highlightTheme.less';

export const CodeEditorWithHighlight = ({ input, language, relationId }) => {
interface Props {
input: string;
relationId: string;
language?: string;
agentId?: string;
command?: string;
}
export const CodeEditorWithHighlight = (props: Props) => {
const { input, language, relationId, agentId, command } = props;
const ref = React.useRef<HTMLDivElement | null>(null);
const monacoCommandRegistry = useInjectable<MonacoCommandRegistry>(MonacoCommandRegistry);
const clipboardService = useInjectable<IClipboardService>(IClipboardService);
Expand Down Expand Up @@ -50,7 +65,15 @@ export const CodeEditorWithHighlight = ({ input, language, relationId }) => {
const handleCopy = useCallback(async () => {
setIsCoping(true);
await clipboardService.writeText(input);
aiReporter.end(relationId, { copy: true });
aiReporter.end(relationId, {
copy: true,
code: input,
language,
agentId,
command,
actionSource: ActionSourceEnum.Chat,
actionType: ActionTypeEnum.ChatCopyCode,
});
runWhenIdle(() => {
setIsCoping(false);
}, 1000);
Expand All @@ -62,7 +85,15 @@ export const CodeEditorWithHighlight = ({ input, language, relationId }) => {
const selection = editor.getSelection();
if (selection) {
insertSnippetWithMonacoEditor(editor, input, [selection], { undoStopBefore: false, undoStopAfter: false });
aiReporter.end(relationId, { insert: true });
aiReporter.end(relationId, {
insert: true,
code: input,
language,
agentId,
command,
actionSource: ActionSourceEnum.Chat,
actionType: ActionTypeEnum.ChatCopyCode,
});
}
}
}, [monacoCommandRegistry]);
Expand Down Expand Up @@ -103,10 +134,14 @@ const CodeBlock = ({
content = '',
relationId,
renderText,
agentId = '',
command = '',
}: {
content?: string;
relationId: string;
renderText?: (t: string) => React.ReactNode;
agentId?: string;
command?: string;
}) => {
const rgInlineCode = /`([^`]+)`/g;
const rgBlockCode = /```([^]+?)```/g;
Expand All @@ -121,7 +156,13 @@ const CodeBlock = ({
return (
<div className={styles.code_block}>
<div className={styles.code_language}>{capitalize(heighLightLang)}</div>
<CodeEditorWithHighlight input={content} language={language} relationId={relationId} />
<CodeEditorWithHighlight
input={content}
language={language}
relationId={relationId}
agentId={agentId}
command={command}
/>
</div>
);
};
Expand Down Expand Up @@ -171,14 +212,16 @@ export const CodeBlockWrapper = ({
text,
renderText,
relationId,
agentId,
}: {
text?: string;
relationId: string;
renderText?: (t: string) => React.ReactNode;
agentId?: string;
}) => (
<div className={styles.ai_chat_code_wrapper}>
<div className={styles.render_text}>
<CodeBlock content={text} renderText={renderText} relationId={relationId} />
<CodeBlock content={text} renderText={renderText} relationId={relationId} agentId={agentId} />
</div>
</div>
);
Expand Down Expand Up @@ -222,7 +265,7 @@ export const CodeBlockWrapperInput = ({
</div>
)}
{command && <div className={styles.tag}>/ {command}</div>}
<CodeBlock content={txt} relationId={relationId} />
<CodeBlock content={txt} relationId={relationId} agentId={agentId} command={command} />
</div>
</div>
);
Expand Down
10 changes: 9 additions & 1 deletion packages/ai-native/src/browser/components/ChatMarkdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import styles from './components.module.less';

interface MarkdownProps {
markdown: IMarkdownString | string;
agentId?: string;
command?: string;
relationId?: string;
className?: string;
fillInIncompleteTokens?: boolean; // 补齐不完整的 token,如代码块或表格
Expand Down Expand Up @@ -45,7 +47,13 @@ export const ChatMarkdown = (props: MarkdownProps) => {
<ConfigProvider value={appConfig}>
<div className={styles.code_block}>
<div className={styles.code_language}>{language}</div>
<CodeEditorWithHighlight input={code} language={language} relationId={props.relationId} />
<CodeEditorWithHighlight
input={code}
language={language}
relationId={props.relationId || ''}
agentId={props.agentId}
command={props.command}
/>
</div>
</ConfigProvider>,
);
Expand Down
22 changes: 20 additions & 2 deletions packages/ai-native/src/browser/components/ChatReply.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import {
import { Icon, getIcon } from '@opensumi/ide-core-browser/lib/components';
import { Loading } from '@opensumi/ide-core-browser/lib/components/ai-native';
import {
ActionSourceEnum,
ActionTypeEnum,
ChatAgentViewServiceToken,
ChatRenderRegistryToken,
ChatServiceToken,
Expand Down Expand Up @@ -47,6 +49,8 @@ interface IChatReplyProps {
relationId: string;
request: ChatRequestModel;
startTime?: number;
agentId?: string;
command?: string;
onRegenerate?: () => void;
onDidChange?: () => void;
onDone?: () => void;
Expand Down Expand Up @@ -159,7 +163,7 @@ const ComponentRender = (props: { component: string; value?: unknown }) => {
};

export const ChatReply = (props: IChatReplyProps) => {
const { relationId, request, startTime = 0, onRegenerate, onDidChange, onDone } = props;
const { relationId, request, startTime = 0, onRegenerate, onDidChange, onDone, agentId, command } = props;

const [, update] = useReducer((num) => (num + 1) % 1_000_000, 0);
const aiReporter = useInjectable<IAIReporter>(IAIReporter);
Expand Down Expand Up @@ -201,6 +205,8 @@ export const ChatReply = (props: IChatReplyProps) => {
replytime: Date.now() - startTime,
success: true,
isStop: false,
command,
agentId,
});
}
update();
Expand All @@ -224,6 +230,8 @@ export const ChatReply = (props: IChatReplyProps) => {
replytime: Date.now() - startTime,
success: false,
isStop: true,
command,
agentId,
});
aiChatService.cancelRequest();
};
Expand Down Expand Up @@ -279,7 +287,17 @@ export const ChatReply = (props: IChatReplyProps) => {
let node: React.ReactNode = null;
if (item.kind === 'reply') {
const a = (
<a onClick={() => chatApiService.sendMessage(chatAgentService.parseMessage(item.message))}>
<a
onClick={() => {
chatApiService.sendMessage({
...chatAgentService.parseMessage(item.message),
reportExtra: {
actionSource: ActionSourceEnum.Chat,
actionType: ActionTypeEnum.Followup,
},
});
}}
>
{item.title || item.message}
</a>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ export const SlashCustomRender = (props: {
relationId: string;
renderContent: TSlashCommandCustomRender;
startTime: number;
agentId?: string;
command?: string;
}) => {
const { userMessage, relationId, requestId, renderContent, startTime } = props;
const { userMessage, relationId, requestId, renderContent, startTime, agentId, command } = props;

const aiChatService = useInjectable<ChatInternalService>(IChatInternalService);
const aiReporter = useInjectable<IAIReporter>(IAIReporter);
Expand All @@ -28,6 +30,8 @@ export const SlashCustomRender = (props: {
replytime: Date.now() - startTime,
success: true,
isStop: false,
agentId,
command,
});
}, [renderContent, requestId, relationId]);

Expand Down
Loading

0 comments on commit 5ccece9

Please sign in to comment.