Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: inline chat & input and support config #4339

Merged
merged 8 commits into from
Feb 6, 2025

Conversation

Ricbet
Copy link
Member

@Ricbet Ricbet commented Feb 5, 2025

Types

  • 🪚 Refactors

Background or solution

  • 新增 inline chat 的 logo 配置,支持图片和 react 组件,传递空或 undefined 则隐藏 logo
  • 新增 inline input 的默认快捷键配置,默认是 ctrlcmd + k
  • 新增 inline input 的默认宽度配置,默认是 320
  • 之前 inline chat 和 inline input 的代码逻辑是耦合的,input 的很多逻辑是由 inline chat 去控制,不合理。现重构成 inline chat 只负责调用 input 的显隐,统一由 input 去控制数据层与渲染层的交互
  • “重新生成” 功能重构:inline input 的重新生成点击后则重新弹出 inline input,并默认回填用户之前输入的文字,以及用户之前选中的代码。inline chat 的重新生成功能不变
  • 支持中断流式输出,中断后保留已输出的结果并展示结果操作栏
  • 流式过程中关闭当前文件,将恢复原始代码并增加提示文案
improve_inline_input.mp4

Changelog

重构 inline input 与 inline chat 的代码

Summary by CodeRabbit

  • 新功能

    • 强化了内联聊天和输入交互,新增了取消操作命令和快捷键绑定,用户可更灵活地中止或切换输入状态。
    • 根据编辑器状态智能显示或隐藏输入窗口,提高了操作便捷性。
  • 界面与样式更新

    • 优化了内联差异预览、提示信息和Logo展示效果,界面更加清晰美观。
  • 配置与本地化

    • 新增内联聊天配置选项(如输入宽度、快捷键、Logo),并完善了中英文提示文本设置。

@Ricbet Ricbet requested review from hacke2 and erha19 February 5, 2025 07:19
@Ricbet Ricbet self-assigned this Feb 5, 2025
@opensumi opensumi bot added the ⚙️ refactor Refactor code label Feb 5, 2025
@Ricbet Ricbet force-pushed the feat/improve-inline-chat branch 2 times, most recently from 015357e to 39a42b8 Compare February 5, 2025 08:10
Copy link

codecov bot commented Feb 5, 2025

Codecov Report

Attention: Patch coverage is 1.47059% with 335 lines in your changes missing coverage. Please review.

Project coverage is 54.18%. Comparing base (0581def) to head (02602f6).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...ser/widget/inline-input/inline-input.controller.ts 0.00% 195 Missing and 31 partials ⚠️
...rowser/widget/inline-input/inline-input.service.ts 0.00% 42 Missing and 9 partials ⚠️
...ai-native/src/browser/widget/inline-input/model.ts 0.00% 14 Missing ⚠️
...widget/inline-chat/inline-chat.feature.registry.ts 0.00% 11 Missing and 2 partials ⚠️
...idget/inline-chat/inline-chat-editor.controller.ts 0.00% 9 Missing and 2 partials ⚠️
...rowser/widget/inline-diff/inline-diff-previewer.ts 0.00% 5 Missing and 3 partials ⚠️
...es/core-browser/src/ai-native/ai-config.service.ts 50.00% 4 Missing and 1 partial ⚠️
.../browser/widget/inline-chat/inline-chat.service.ts 0.00% 2 Missing ⚠️
packages/core-browser/src/contextkey/ai-native.ts 0.00% 2 Missing ⚠️
...kages/ai-native/src/browser/ai-core.contextkeys.ts 0.00% 1 Missing ⚠️
... and 2 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4339      +/-   ##
==========================================
- Coverage   54.23%   54.18%   -0.05%     
==========================================
  Files        1638     1639       +1     
  Lines      100155   100243      +88     
  Branches    21738    21751      +13     
==========================================
  Hits        54320    54320              
- Misses      38087    38157      +70     
- Partials     7748     7766      +18     
Flag Coverage Δ
jsdom 49.66% <1.47%> (-0.05%) ⬇️
node 12.28% <0.00%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Ricbet Ricbet force-pushed the feat/improve-inline-chat branch from 39a42b8 to af886a0 Compare February 6, 2025 03:24
@Ricbet Ricbet changed the title WIP: refactor: inline chat & input and support config refactor: inline chat & input and support config Feb 6, 2025
@erha19
Copy link
Member

erha19 commented Feb 6, 2025

image

输出过程的样式感觉可以优化一下只留一个 loading 就行了,另外这里好像重复展示 Hover 和 Input 组件了

@Ricbet
Copy link
Member Author

Ricbet commented Feb 6, 2025

image 输出过程的样式感觉可以优化一下只留一个 loading 就行了,另外这里好像重复展示 Hover 和 Input 组件了

done

Copy link
Contributor

coderabbitai bot commented Feb 6, 2025

Walkthrough

此次 PR 主要针对 AI 原生模块的多个组件和服务进行重构和扩展,涉及内联聊天与输入功能的逻辑调整。具体改动包括新增上下文键、服务类重命名、方法签名更新、新命令与事件的添加,以及样式和配置项的更新。此外,对 diff 预览、内联提示、内联输入组件及其模型进行了重构,为内联输入的流式处理和交互管理提供了新的实现路径,同时调整了相关导入和依赖。

Changes

File(s) 更改摘要
packages/ai-native/src/browser/ai-core.contextkeys.ts
packages/ai-native/src/browser/ai-core.contribution.ts
packages/ai-native/src/browser/index.ts
新增上下文键 inlineInputWidgetIsStreaming,添加新命令 AI_INLINE_CHAT_INTERACTIVE_INPUT_CANCEL,更新服务依赖与命令执行逻辑,使用新的服务实现替换旧服务。
packages/ai-native/src/browser/widget/inline-chat/inline-chat-editor.controller.ts
packages/ai-native/src/browser/widget/inline-chat/inline-chat.feature.registry.ts
packages/ai-native/src/browser/widget/inline-chat/inline-chat.service.ts
packages/ai-native/src/browser/widget/inline-chat/inline-content-widget.tsx
内联聊天相关:更新服务类型(由 AIInlineChatService 切换为 InlineChatService),增加逻辑判断防止与内联输入冲突,调整事件与方法实现,简化交互逻辑。
packages/ai-native/src/browser/widget/inline-diff/inline-diff-previewer.ts 为 diff 预览功能添加多个新方法(如 mount、getPosition、onReady、show、setValue/getValue、onLineCount、onData、onError、onAbort、onEnd),并调整 LiveInlineDiffPreviewer 的节点管理与操作处理。
packages/ai-native/src/browser/widget/inline-hint/inline-hint.controller.ts 移除 inlineInputChatService 相关属性与方法,取消对内联输入服务的引用。
packages/ai-native/src/browser/widget/inline-input/inline-input-widget.tsx
packages/ai-native/src/browser/widget/inline-input/inline-input.controller.ts
packages/ai-native/src/browser/widget/inline-input/inline-input.service.ts
packages/ai-native/src/browser/widget/inline-input/model.ts
内联输入相关:重构组件与服务,新增 defaultValue 属性、事件发射器,新方法(如 showInputInEmptyLine、showInputInSelection、visibleBy… 系列),并增加 InteractiveInputModel 类来管理交互输入处理。
packages/core-browser/src/ai-native/ai-config.service.ts
packages/core-browser/src/ai-native/command.ts
更新配置服务:新增默认 inline chat 配置(DEFAULT_INLINE_CHAT_CONFIG),引入 inlineChat getter,并添加取消交互输入的命令常量。
packages/core-browser/src/components/ai-native/ai-action/index.module.less
packages/core-browser/src/components/ai-native/ai-action/index.tsx
更新样式和组件:新增 logo_container、嵌套 ai_action_icon 与 operate_item 样式,调整 logo 渲染逻辑,集成 AINativeConfigService。
packages/core-browser/src/components/ai-native/interactive-input/index.tsx 为交互输入组件接口增加 defaultValue 属性,并修改 internalValue 的初始状态逻辑。
packages/core-browser/src/contextkey/ai-native.ts 新增并调整上下文键:增加 InlineInputWidgetIsStreaming 常量,同时调整 InlineInputWidgetIsVisible 的声明位置。
packages/core-common/src/types/ai-native/index.ts 新增接口 IAINativeInlineChatConfig,并在 IAINativeConfig 与 IDesignLayoutConfig 中增加相关属性(如 supportExternalChatPanel、inlineChat),同时对 layout 属性添加弃用说明。
packages/i18n/src/common/en-US.lang.ts
packages/i18n/src/common/zh-CN.lang.ts
分别为英文和中文本地化文件新增内联聊天相关的条目(如操作标题、生成取消提示、输入占位符)。
packages/overlay/src/browser/message.service.tsx 删除 vscode 类型导入。
packages/startup/entry/web/render-app.tsx 调整 import 顺序及布局配置,将 AI_CHAT_LOGO_AVATAR_ID 纳入 DESIGN_MENU_BAR_RIGHT 模块。

Sequence Diagram(s)

sequenceDiagram
    participant U as 用户
    participant IC as InlineInputController
    participant IS as InlineInputService
    participant LPS as LanguageParserService
    participant E as 编辑器

    U->>IC: 触发内联输入(点击/选中)
    IC->>IS: 调用 showInputInEmptyLine/Selection 方法
    IS->>LPS: 查找最近代码块 (visibleByNearestCodeBlock)
    LPS-->>IS: 返回代码块信息
    IS->>IC: 触发 onInteractiveInputVisibleInSelection 事件
    IC->>E: 更新内联输入显示状态
Loading
sequenceDiagram
    participant U as 用户操作
    participant ICE as InlineChatEditorController
    participant CT as ContextKey 服务

    U->>ICE: 触发 mount 事件
    ICE->>CT: 检查 inlineInputWidgetIsVisible 与 inlineInputWidgetIsStreaming
    alt 存在活动的内联输入
      CT-->>ICE: 返回 true
      ICE->>ICE: 阻止内联聊天显示
    else 无内联输入活动
      CT-->>ICE: 返回 false
      ICE->>ICE: 展示内联聊天
    end
Loading

Possibly related PRs

Suggested labels

🎨 feature

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

yarn install v1.22.22
[1/4] Resolving packages...
warning [email protected]: This version is no longer supported. Please see https://eslint.org/version-support for other options.
warning eslint > @humanwhocodes/[email protected]: Use @eslint/config-array instead
warning eslint > @humanwhocodes/config-array > @humanwhocodes/[email protected]: Use @eslint/object-schema instead
warning eslint > file-entry-cache > flat-cache > [email protected]: Rimraf versions prior to v4 are no longer supported
warning eslint > file-entry-cache > flat-cache > rimraf > [email protected]: Glob versions prior to v9 are no longer supported
warning eslint > file-entry-cache > flat-cache > rimraf > glob > [email protected]: This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful.
warning eslint-import-resolver-typescript > [email protected]: Glob versions prior to v9 are no longer supported
error Couldn't find any versions for "@opensumi/ide-dev-tool" that matches "workspace:*"
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.

Tip

🌐 Web search-backed reviews and chat
  • We have enabled web search-based reviews and chat for all users. This feature allows CodeRabbit to access the latest documentation and information on the web.
  • You can disable this feature by setting web_search: false in the knowledge_base settings.
  • Please share any feedback in the Discord discussion.
✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

🧹 Nitpick comments (10)
packages/ai-native/src/browser/widget/inline-diff/inline-diff-previewer.ts (2)

257-270: 建议避免使用非空断言运算符 '!'

SideBySideInlineDiffWidget 类的 onData 方法中,使用了 this.node?.getModifiedModel()!。为了提高代码的健壮性,建议避免使用非空断言运算符,改为添加适当的空值检查,确保 modifiedModel 不为 undefined,以防止潜在的运行时错误。


395-397: 建议在 onData 方法中增加节点存在性检查

LiveInlineDiffPreviewer 类的 onData 方法中,调用了 this.node?.addLinesToDiff(...)。虽然使用了可选链操作符,但为了代码的可读性和可靠性,建议显式检查 this.node 是否存在,或者确保在调用前 this.node 已被正确初始化。

packages/ai-native/src/browser/widget/inline-input/inline-input.controller.ts (1)

247-339: 建议:提取公共逻辑,减少代码重复

showInputInEmptyLineshowInputInSelection 方法中存在大量相似的代码,尤其是在处理 inlineInputChatWidget 的事件监听和 inputDisposable 的管理上。建议将这些重复的代码提取到一个私有方法中,以提高代码的可维护性和可读性。

Also applies to: 374-453

packages/ai-native/src/browser/widget/inline-input/model.ts (1)

23-25: 建议添加参数类型检查

setStrategyHandler 方法中,建议添加参数非空检查以提高代码健壮性。

 public setStrategyHandler(fn: TRunStrategyFn): void {
+  if (!fn) {
+    throw new Error('Strategy handler cannot be undefined');
+  }
   this._strategyHandler = fn;
 }
packages/core-browser/src/components/ai-native/ai-action/index.tsx (1)

96-108: Logo 渲染逻辑优化

新增的 Logo 渲染逻辑具有良好的扩展性,支持多种类型的 logo 配置:

  • 字符串类型的图片 URL
  • React 元素
  • 函数组件

建议添加类型验证以提高代码健壮性。

 const Logo = useMemo(() => {
   const InlineChatLogo = aiNativeConfigService.inlineChat.logo;
+  if (!InlineChatLogo) {
+    return null;
+  }
 
   if (typeof InlineChatLogo === 'string') {
     return <img src={InlineChatLogo} className={styles.ai_action_icon} />;
   } else if (React.isValidElement(InlineChatLogo)) {
     return InlineChatLogo;
   } else if (typeof InlineChatLogo === 'function') {
     return <InlineChatLogo />;
   }
 
   return null;
 }, [aiNativeConfigService.inlineChat.logo]);
packages/core-common/src/types/ai-native/index.ts (1)

69-82: 新增内联聊天配置接口

IAINativeInlineChatConfig 接口设计合理,提供了完整的类型定义:

  • inputWidth: 控制输入框宽度
  • inputKeybinding: 自定义快捷键
  • logo: 支持多种类型的 logo 配置

建议为 inputWidth 添加单位说明。

 export interface IAINativeInlineChatConfig {
   /**
-   * inline chat 的 input 默认宽度
+   * inline chat 的 input 默认宽度(单位:像素)
    */
   inputWidth?: number;
   /**
    * 唤起 input 的默认快捷键
    */
   inputKeybinding?: string;
   /**
    * inline chat 的 logo,支持图片和 react 组件
    */
   logo?: string | React.ReactNode | React.ComponentType<any>;
 }
packages/core-browser/src/components/ai-native/ai-action/index.module.less (1)

13-37: 建议优化 loading 状态的样式实现

当前的实现方式可以改进:

  • loading_mask 使用绝对定位可能导致在某些场景下的定位问题
  • 硬编码的左边距(18px)不够灵活

建议如下改进:

.loading_mask {
  cursor: not-allowed;
  position: absolute;
  z-index: 1;
-  left: 18px;
+  left: var(--loading-mask-offset, 18px);
  right: 0;
  height: 100%;
  background-color: var(--kt-input-disableBackground);
+  display: flex;
+  align-items: center;
}
packages/ai-native/src/browser/widget/inline-chat/inline-content-widget.tsx (3)

24-25: 服务解耦和重命名改进了架构设计!

AIInlineChatService 重命名为 InlineChatService 并引入独立的 InlineInputService,体现了更好的关注点分离,使得内联聊天和输入功能各司其职。

Also applies to: 29-29


115-115: 优化 renderContent 的依赖数组

renderContent 回调函数的依赖数组中使用了 status,但函数内部使用的是通过 status 计算的 isErrorisDone。建议修改依赖数组以匹配实际使用的变量。

-  }, [operationList, moreOperation, onResultClick, status]);
+  }, [operationList, moreOperation, onResultClick, isError, isDone, isLoading, handleClickActions, handleClose]);

176-182: 建议添加方法文档说明交互逻辑

clickActionId 方法在处理 InteractiveInputModel.ID 时的行为(隐藏当前widget并显示input widget)值得添加详细的文档说明。

+  /**
+   * 处理动作点击事件
+   * @param actionId 动作ID
+   * @param source 事件来源
+   * 
+   * 特殊处理:
+   * - 当 actionId 为 InteractiveInputModel.ID 时,会隐藏当前的 inline chat widget
+   *   并通过 inlineInputService 显示 inline input widget
+   */
   public clickActionId(actionId: string, source: string): void {
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0581def and 02602f6.

📒 Files selected for processing (24)
  • packages/ai-native/src/browser/ai-core.contextkeys.ts (3 hunks)
  • packages/ai-native/src/browser/ai-core.contribution.ts (10 hunks)
  • packages/ai-native/src/browser/index.ts (2 hunks)
  • packages/ai-native/src/browser/widget/inline-chat/inline-chat-editor.controller.ts (7 hunks)
  • packages/ai-native/src/browser/widget/inline-chat/inline-chat.feature.registry.ts (4 hunks)
  • packages/ai-native/src/browser/widget/inline-chat/inline-chat.service.ts (1 hunks)
  • packages/ai-native/src/browser/widget/inline-chat/inline-content-widget.tsx (4 hunks)
  • packages/ai-native/src/browser/widget/inline-diff/inline-diff-previewer.ts (9 hunks)
  • packages/ai-native/src/browser/widget/inline-hint/inline-hint.controller.ts (1 hunks)
  • packages/ai-native/src/browser/widget/inline-input/inline-input-widget.tsx (5 hunks)
  • packages/ai-native/src/browser/widget/inline-input/inline-input.controller.ts (2 hunks)
  • packages/ai-native/src/browser/widget/inline-input/inline-input.service.ts (1 hunks)
  • packages/ai-native/src/browser/widget/inline-input/model.ts (1 hunks)
  • packages/core-browser/src/ai-native/ai-config.service.ts (4 hunks)
  • packages/core-browser/src/ai-native/command.ts (1 hunks)
  • packages/core-browser/src/components/ai-native/ai-action/index.module.less (3 hunks)
  • packages/core-browser/src/components/ai-native/ai-action/index.tsx (5 hunks)
  • packages/core-browser/src/components/ai-native/interactive-input/index.tsx (1 hunks)
  • packages/core-browser/src/contextkey/ai-native.ts (1 hunks)
  • packages/core-common/src/types/ai-native/index.ts (1 hunks)
  • packages/i18n/src/common/en-US.lang.ts (1 hunks)
  • packages/i18n/src/common/zh-CN.lang.ts (1 hunks)
  • packages/overlay/src/browser/message.service.tsx (0 hunks)
  • packages/startup/entry/web/render-app.tsx (1 hunks)
💤 Files with no reviewable changes (1)
  • packages/overlay/src/browser/message.service.tsx
⏰ Context from checks skipped due to timeout of 90000ms (8)
  • GitHub Check: unittest (ubuntu-latest, 18.x, jsdom)
  • GitHub Check: unittest (ubuntu-latest, 18.x, node)
  • GitHub Check: unittest (macos-latest, 18.x, jsdom)
  • GitHub Check: unittest (macos-latest, 18.x, node)
  • GitHub Check: build (ubuntu-latest, 20.x)
  • GitHub Check: build (macos-latest, 20.x)
  • GitHub Check: ubuntu-latest, Node.js 20.x
  • GitHub Check: build-windows
🔇 Additional comments (28)
packages/ai-native/src/browser/widget/inline-chat/inline-chat.feature.registry.ts (1)

114-142: 代码重构清晰,职责划分明确

registerInteractiveInput 方法的重构通过使用 InlineInputService,使代码结构更加清晰,职责划分更为明确。这符合模块化设计的最佳实践,增强了代码的可维护性和可扩展性。

packages/ai-native/src/browser/widget/inline-input/inline-input.controller.ts (1)

128-131: 确认取消流式操作后的状态一致性

cancelToken 方法中,除了设置 inlineInputWidgetIsStreamingfalse,还需要确保其他与流式操作相关的状态也被正确重置。例如,检查是否需要重置界面上的加载状态或进度指示器。

packages/ai-native/src/browser/widget/inline-chat/inline-chat.service.ts (1)

8-18: 代码重构合理,命名清晰

AIInlineChatService 重命名为 InlineChatService,并相应地调整了事件和方法,符合模块职责分离的原则,代码命名更加清晰明确。

packages/core-browser/src/contextkey/ai-native.ts (1)

9-11: 新增上下文键定义规范

添加了新的上下文键 InlineInputWidgetIsStreaming,用于表示内联输入控件的流式状态。定义规范,符合上下文键的命名和使用规范。

packages/core-browser/src/ai-native/command.ts (1)

9-11: 命令常量定义正确!

新增的取消命令常量遵循了现有的命名规范,并且与其他内联聊天相关命令保持一致。

packages/core-browser/src/ai-native/ai-config.service.ts (1)

25-29: 默认配置设置合理!

默认的内联聊天配置包含了必要的参数,并且使用了合理的默认值:

  • 输入框宽度设置为 320px 适合大多数使用场景
  • 快捷键组合 'ctrlcmd+k' 符合用户习惯
  • 默认 logo 组件的使用保持了界面一致性
packages/ai-native/src/browser/ai-core.contextkeys.ts (1)

26-26: 上下文键集成完善!

新增的 inlineInputWidgetIsStreaming 上下文键:

  • 正确集成到了现有的上下文键系统中
  • 遵循了统一的初始化模式
  • 为流式处理状态提供了必要的追踪能力

Also applies to: 39-39

packages/ai-native/src/browser/widget/inline-hint/inline-hint.controller.ts (1)

1-119: 代码重构改进了关注点分离

移除 inlineInputChatService 的依赖使得内联提示控制器的职责更加清晰,这与 PR 的重构目标保持一致。

packages/ai-native/src/browser/widget/inline-input/inline-input-widget.tsx (3)

17-24: 接口扩展支持默认值配置

通过 defaultValue 属性的添加,提高了组件的可配置性和灵活性。


89-94: 事件处理机制的改进

新增的事件发射器 _onInteractiveInputValue_onClose 使组件能够更好地与外部系统进行交互。


75-75: 使用配置服务优化维护性

从硬编码宽度值切换到使用 aiNativeConfigService.inlineChat.inputWidth 提高了代码的可维护性。

packages/startup/entry/web/render-app.tsx (1)

100-102: AI 聊天图标集成到菜单栏

AI_CHAT_LOGO_AVATAR_ID 添加到 DESIGN_MENU_BAR_RIGHT 模块数组中,合理地集成了 AI 聊天功能的视觉元素。

packages/ai-native/src/browser/index.ts (1)

92-94: 服务重命名提升代码清晰度

AIInlineChatService 重命名为 InlineChatService 使命名更加简洁,同时保持了依赖注入的正确配置。

packages/core-browser/src/components/ai-native/ai-action/index.tsx (2)

86-86: 依赖注入优化

使用 useInjectable 注入 AINativeConfigService 服务,符合依赖注入最佳实践。


158-158: 条件渲染优化

合理使用条件渲染 Logo 和分隔线,提高了组件的灵活性。

packages/core-browser/src/components/ai-native/interactive-input/index.tsx (2)

48-48: 新增默认值属性

IInteractiveInputProps 接口中添加 defaultValue 属性,增强了组件的可配置性。


55-55: 状态管理优化

使用 defaultValue || props.value || '' 的优先级顺序初始化内部状态,符合 React 受控组件的最佳实践。

packages/core-common/src/types/ai-native/index.ts (1)

86-89: 废弃提示优化

使用 @deprecated 标记废弃属性,并提供明确的替代方案,有助于代码维护。

packages/ai-native/src/browser/widget/inline-chat/inline-chat-editor.controller.ts (3)

55-57: 服务类型更改提升了模块化程度

aiInlineChatService 的类型从 AIInlineChatService 更改为 InlineChatService 有助于更好地分离关注点。


203-212: 方法可见性修改增强了灵活性

disposeAllWidget 从私有方法改为公共方法使其可以被外部组件调用,提高了代码的可重用性。


230-240: 新增内联输入可见性检查增强了用户体验

添加了对 inlineInputWidgetIsVisibleinlineInputWidgetIsStreaming 的检查,避免了内联聊天和输入组件的冲突。

packages/ai-native/src/browser/ai-core.contribution.ts (2)

427-461: 命令执行逻辑优化提升了用户体验

内联输入显示命令的执行逻辑得到了增强:

  • 先隐藏内联聊天,避免界面冲突
  • 基于编辑器状态和光标位置智能决定显示位置
  • 支持空行和选中文本的不同处理逻辑

463-470: 新增取消命令增强了用户控制

添加了 AI_INLINE_CHAT_INTERACTIVE_INPUT_CANCEL 命令,使用户可以随时取消正在进行的内联输入操作。

packages/i18n/src/common/zh-CN.lang.ts (1)

1228-1235: 新增本地化字符串完善了用户界面反馈

添加了以下中文本地化字符串:

  • 内联聊天操作标题
  • 输入占位符提示
  • 生成取消提示

这些字符串使用户界面更加友好和完整。

packages/i18n/src/common/en-US.lang.ts (1)

1460-1467: 新增的内联聊天本地化字符串看起来不错!

这些字符串提供了良好的用户体验,特别是:

  • 使用参数化的标题格式 Chat({0}),支持动态内容
  • 清晰的操作取消提示信息
packages/core-browser/src/components/ai-native/ai-action/index.module.less (2)

49-57: logo_container 的样式实现看起来不错!

良好的实践:

  • 使用固定尺寸(16x16)确保一致的显示效果
  • 使用 object-fit: cover 确保图片正确填充容器
  • 使用 inherit 继承宽度保持灵活性

80-85: operate_item 的样式设计合理!

良好的实践:

  • 使用统一的高度和行高(24px)
  • 适当的内边距(6px)和圆角(4px)提供了良好的视觉效果
  • 样式与整体设计语言保持一致
packages/ai-native/src/browser/widget/inline-chat/inline-content-widget.tsx (1)

127-128: 依赖注入使用得当!

使用 @Autowired 装饰器注入 InlineInputService 符合依赖注入的最佳实践。

@Ricbet
Copy link
Member Author

Ricbet commented Feb 6, 2025

/next

@opensumi
Copy link
Contributor

opensumi bot commented Feb 6, 2025

🎉 PR Next publish successful!

3.7.1-next-1738824147.0

@Ricbet Ricbet merged commit 44b56d6 into main Feb 6, 2025
13 checks passed
@Ricbet Ricbet deleted the feat/improve-inline-chat branch February 6, 2025 07:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
⚙️ refactor Refactor code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants