Skip to content

feat(react-ui): expose selectedImages via useCopilotChatImageUploads hook#1

Open
oxyflour wants to merge 1 commit into
mainfrom
codex/add-hook-for-external-access-to-selectedimages
Open

feat(react-ui): expose selectedImages via useCopilotChatImageUploads hook#1
oxyflour wants to merge 1 commit into
mainfrom
codex/add-hook-for-external-access-to-selectedimages

Conversation

@oxyflour

Copy link
Copy Markdown
Owner

Motivation

  • 需要让 CopilotChat 中维护的 selectedImages 状态能够被组件树外部的子组件访问和操作,从而支持自定义上传/预览/提交等场景。

Description

  • 新增 CopilotChatImageUploadsContext 并导出钩子 useCopilotChatImageUploads,通过上下文向下提供 selectedImagessetSelectedImagesclearSelectedImagesremoveSelectedImage
  • CopilotChat 内实现并复用 clearSelectedImages 方法以统一清空图片队列与重置文件输入框状态,并把该方法用于发送消息的清理流程(handleSendMessage)。
  • 使用 CopilotChatImageUploadsContext.Provider 包裹原有渲染树以确保 hook 在 CopilotChat 子树中可用。
  • packages/v1/react-ui/src/components/chat/index.tsx 中导出 useCopilotChatImageUploads 以便外部直接 import 使用。

Testing

  • 格式化校验:运行 pnpm prettier --write packages/v1/react-ui/src/components/chat/Chat.tsx packages/v1/react-ui/src/components/chat/index.tsx 成功。
  • 类型检查:运行 pnpm nx run @copilotkit/react-ui:check-types 在该环境中失败,失败原因为工作区模块解析限制(例如 @copilotkit/react-core / @copilotkit/runtime-client-gql 无法解析)以及其它与本变更无关的现有类型错误。
  • 构建:运行 pnpm nx run @copilotkit/react-ui:build --excludeTaskDependencies 时 JavaScript 构建成功但 DTS(类型声明生成)在当前环境下因同样的模块解析问题失败。

Codex Task

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant