From a1d8f3eb0f0b99a1d303dc9017b9c5fb5bd17d75 Mon Sep 17 00:00:00 2001 From: suyao Date: Tue, 23 Sep 2025 06:15:33 +0800 Subject: [PATCH] Implement InputbarTools registry system for tool management - Add ToolDefinition interface and registry mechanism with dependency injection - Create InputbarToolsProvider for shared state management (files, mentionedModels, etc.) - Migrate existing tools to registry-based definitions and simplify component props --- src/renderer/src/pages/home/Inputbar/TODO.md | 67 +++++++++++++++++++- 1 file changed, 64 insertions(+), 3 deletions(-) diff --git a/src/renderer/src/pages/home/Inputbar/TODO.md b/src/renderer/src/pages/home/Inputbar/TODO.md index 117b246dc1..f233f2a40c 100644 --- a/src/renderer/src/pages/home/Inputbar/TODO.md +++ b/src/renderer/src/pages/home/Inputbar/TODO.md @@ -10,12 +10,34 @@ Create a single configurable input bar that supports chat topics, agent sessions - [ ] Define per-scope options (features toggles, placeholders, min/max rows, token counter, quick panel, attachments, knowledge picker, mention models, translate button, abort button, etc.). - [ ] Register defaults for chat (`TopicType.Chat`), agent session (`TopicType.Session`), and mini window scope. -### 2. Shared UI Composer +### 2. InputbarTools Registry System (NEW) +- [ ] Create `ToolDefinition` interface with key, label, icon, condition, dependencies, and render function +- [ ] Implement tool registration mechanism in `src/renderer/src/config/registry/inputbarTools.ts` +- [ ] Create `InputbarToolsProvider` for shared state management (files, mentionedModels, knowledgeBases, etc.) +- [ ] Define tool context interfaces (`ToolContext`, `ToolRenderContext`) for dependency injection +- [ ] Migrate existing tools to registry-based definitions: + - [ ] new_topic tool + - [ ] attachment tool + - [ ] thinking tool + - [ ] web_search tool + - [ ] url_context tool + - [ ] knowledge_base tool + - [ ] mcp_tools tool + - [ ] generate_image tool + - [ ] mention_models tool + - [ ] quick_phrases tool + - [ ] clear_topic tool + - [ ] toggle_expand tool + - [ ] new_context tool +- [ ] Simplify InputbarTools component to use registry (reduce from 19 props to 3-5) +- [ ] Integrate tool visibility/order configuration with InputbarScope + +### 3. Shared UI Composer - [ ] Extract common UI from `Inputbar.tsx` into new `InputComposer` component that reads config + callbacks. - [ ] Ensure composer handles textarea sizing, focus, drag/drop, token estimation, attachments, toolbar slots based on config. - [ ] Provide controlled props for text, files, mentioned models, loading states, quick panel interactions. -### 3. Chat Wrapper Migration +### 4. Chat Wrapper Migration - [ ] Refactor `Inputbar.tsx` to: - Resolve scope via topic type. - Fetch config via registry. @@ -23,7 +45,7 @@ Create a single configurable input bar that supports chat topics, agent sessions - Remove inline UI duplication now covered by composer. - [ ] Verify chat-specific behaviour (knowledge save, auto translate, quick panel, model mentions) via config flags and callbacks. -### 4. Agent Session Wrapper Migration +### 5. Agent Session Wrapper Migration - [ ] Rebuild session input bar (currently `AgentSessionInputbar.tsx`) as thin wrapper using composer and session scope config. - [ ] Use session-specific hooks for message creation, model resolution, aborting, and streaming state. - [ ] Once parity confirmed, delete `AgentSessionInputbar.tsx` and update all imports. @@ -42,3 +64,42 @@ Create a single configurable input bar that supports chat topics, agent sessions - Aligns with the approach taken for `MessageMenubar` scope registry. - Composer should accept refs for external focus triggers (e.g. `MessageGroup` or session auto-focus). - Plan to remove now-unused session-specific styles/components once migration completes. + +## Implementation Details + +### InputbarTools Registry Architecture +**Problem**: Current InputbarTools has 19 props causing severe prop drilling and coupling. + +**Solution**: Registry-based tool system with dependency injection: + +```typescript +// Tool Definition +interface ToolDefinition { + key: string + label: string | ((t: TFunction) => string) + icon?: React.ComponentType + condition?: (context: ToolContext) => boolean + visibleInScopes?: InputbarScope[] + dependencies?: { hooks?, refs?, state? } + render: (context: ToolRenderContext) => ReactNode +} + +// Context Provider for shared state +InputbarToolsProvider manages: +- files, mentionedModels, knowledgeBases states +- setText, resizeTextArea actions +- Tool refs management + +// Simplified Component Interface +InputbarTools props reduced to: +- scope: InputbarScope +- assistantId: string +- onNewContext?: () => void +``` + +**Benefits**: +- Decoupled tool definitions +- Easy to add/remove tools per scope +- Type-safe dependency injection +- Maintains drag-drop functionality +- Reduces component complexity from 19 to 3-5 props