Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 | import { HeroUIProvider } from "@heroui/react" import { DEFAULT_AUTO_APPROVAL_SETTINGS } from "@shared/AutoApprovalSettings" import type { ApiConfiguration } from "@shared/api" import type { AiHydroMessage } from "@shared/ExtensionMessage" import type { HistoryItem } from "@shared/HistoryItem" import type { Meta, StoryObj } from "@storybook/react-vite" import { useMemo } from "react" import { expect, userEvent, within } from "storybook/test" import { ExtensionStateContext, useExtensionState } from "@/context/ExtensionStateContext" import ChatView from "./components/chat/ChatView" import WelcomeView from "./components/welcome/WelcomeView" // Mock component that mimics App behavior but works in Storybook const MockApp = () => { const { showWelcome } = useExtensionState() return ( <HeroUIProvider> {showWelcome ? ( <WelcomeView /> ) : ( <ChatView hideAnnouncement={() => {}} isHidden={false} showAnnouncement={false} showHistoryView={() => {}} /> )} </HeroUIProvider> ) } // Constants const SIDEBAR_CLASS = "flex flex-col justify-center h-[60%] w-[80%] overflow-hidden" const ExtensionStateProviderMock = ExtensionStateContext.Provider const meta: Meta<typeof MockApp> = { title: "Views/Chat", component: MockApp, parameters: { layout: "fullscreen", docs: { description: { component: ` The ChatView component is the main interface for interacting with AI-Hydro. It provides a comprehensive chat experience with AI assistance, task management, and various tools. **Key Features:** - **Task Management**: Create, resume, and manage AI-assisted tasks - **Message History**: View conversation history with rich formatting - **File & Image Support**: Attach files and images to messages - **Tool Integration**: Execute commands, browse files, and use various tools - **Auto-approval**: Configure automatic approval for certain actions - **Streaming Responses**: Real-time AI response streaming - **Context Management**: Intelligent conversation context handling - **Plan/Act Modes**: Separate planning and execution phases - **MCP Integration**: Model Context Protocol server support - **Browser Automation**: Automated browser interactions - **Checkpoint System**: Save and restore conversation states **Use Cases:** - Software development assistance - Code review and refactoring - File system operations - Web browsing and research - Task automation - Learning and exploration **Note**: In Storybook, some features like file operations, command execution, and API calls are mocked for demonstration purposes. `, }, }, }, decorators: [ (Story) => ( <div className="w-full h-full flex justify-center items-center overflow-hidden"> <div className={SIDEBAR_CLASS}> <Story /> </div> </div> ), ], } export default meta type Story = StoryObj<typeof MockApp> // Mock data factories const createApiConfig = (overrides: Partial<ApiConfiguration> = {}): ApiConfiguration => ({ actModeApiProvider: "anthropic", actModeApiModelId: "claude-3-5-sonnet-20241022", actModeOpenRouterModelInfo: { maxTokens: 8000, contextWindow: 200000, supportsPromptCache: true, }, apiKey: "mock-key", ...overrides, }) const mockApiConfiguration = createApiConfig() const mockApiConfigurationPlan = createApiConfig({ planModeApiProvider: "anthropic", planModeApiModelId: "claude-3-5-sonnet-20241022", }) const createHistoryItem = (id: string, hoursAgo: number, task: string, metrics: Partial<HistoryItem> = {}): HistoryItem => ({ id, ulid: "01HZZZ1A1B2C3D4E5F6G7H8J9K", ts: Date.now() - hoursAgo * 3600000, task, tokensIn: 2500, tokensOut: 1200, cacheWrites: 350, cacheReads: 180, totalCost: 0.085, size: 123456, ...metrics, }) const mockTaskHistory: HistoryItem[] = [ createHistoryItem("task-1", 1, "Create a React component for displaying user profiles"), createHistoryItem("task-2", 2, "Debug the authentication flow in the login system", { tokensIn: 3200, tokensOut: 1800, cacheWrites: 450, cacheReads: 220, totalCost: 0.125, size: 1234567, }), createHistoryItem("task-3", 24, "Optimize database queries for better performance", { tokensIn: 4500, tokensOut: 2400, cacheWrites: 680, cacheReads: 340, totalCost: 0.185, size: 12345678, }), ] const createMessage = ( minutesAgo: number, type: AiHydroMessage["type"], say: AiHydroMessage["say"], text: string, overrides: Partial<AiHydroMessage> = {}, ): AiHydroMessage => ({ ts: Date.now() - minutesAgo * 60000, type, say, text, ...overrides, }) const createApiReqMessage = (minutesAgo: number, request: string, metrics: any = {}) => createMessage( minutesAgo, "say", "api_req_started", JSON.stringify({ request, tokensIn: 19500, tokensOut: 4220, cacheWrites: 120, cacheReads: 60, size: 12345, cost: 0.025, ...metrics, }), ) const mockActiveMessages: AiHydroMessage[] = [ createMessage(5, "say", "task", "Help me create a responsive navigation component for a React application"), createApiReqMessage(4.9, "Initial analysis request"), createMessage( 4.7, "say", "text", "I'll help you create a responsive navigation component for your React application. Let me start by examining your current project structure and then create a modern, accessible navigation component.", ), createMessage(4.3, "say", "tool", JSON.stringify({ tool: "listFilesTopLevel", path: "src/components" })), createApiReqMessage(4.2, "Component creation request", { tokensIn: 12020, tokensOut: 6180, cost: 0.042 }), createMessage( 4, "say", "text", "Based on your project structure, I'll create a responsive navigation component with the following features:\n\n- Mobile-first responsive design\n- Accessible keyboard navigation\n- Smooth animations\n- Support for nested menu items\n- Dark/light theme support", ), createMessage( 3.7, "say", "tool", JSON.stringify({ tool: "newFileCreated", path: "src/components/Navigation/Navigation.tsx", content: "// Navigation component code...", }), ), createApiReqMessage(3.5, "Final response request", { tokensIn: 41550, tokensOut: 3320, cost: 0.018 }), createMessage( 3.3, "say", "text", "I've created a responsive navigation component with TypeScript support. The component includes:\n\n✅ Mobile-first responsive design\n✅ Accessible ARIA attributes\n✅ Toggle functionality for mobile\n✅ TypeScript interfaces for type safety\n✅ Theme support\n\nWould you like me to also create the CSS styles for this component?", ), ] const mockStreamingMessages: AiHydroMessage[] = [ ...mockActiveMessages, createMessage( 0.17, "say", "text", "Now I'll create the CSS styles for the navigation component. This will include responsive breakpoints, smooth animations, and accessibility features...", { partial: true }, ), ] // Reusable state and decorator factories const createMockState = (overrides: any = {}) => ({ ...useExtensionState(), useAutoCondense: true, autoCondenseThreshold: 0.5, welcomeViewCompleted: true, showWelcome: false, aihydroMessages: mockActiveMessages, taskHistory: mockTaskHistory, apiConfiguration: mockApiConfiguration, ...overrides, }) const createStoryDecorator = (stateOverrides: any = {}) => (Story: any) => { const mockState = useMemo(() => createMockState(stateOverrides), []) return ( <ExtensionStateProviderMock value={mockState}> <div className="w-full h-full flex justify-center items-center overflow-hidden"> <div className={SIDEBAR_CLASS}> <Story /> </div> </div> </ExtensionStateProviderMock> ) } export const WelcomeScreen: Story = { decorators: [createStoryDecorator({ welcomeViewCompleted: false, showWelcome: true, aihydroMessages: [] })], parameters: { docs: { description: { story: "The welcome screen shown to new users or when no task is active. Displays quick start options and recent task history.", }, }, }, args: {}, // More on component testing: https://storybook.js.org/docs/writing-tests/interaction-testing play: async ({ canvasElement }) => { const canvas = within(canvasElement) // Button has vscode-button element name const getStartedButton = canvas.getByText("Get Started for Free") const byokButton = canvas.getByText("Use your own API key") await expect(getStartedButton).toBeInTheDocument() await expect(byokButton).toBeInTheDocument() await userEvent.click(byokButton) await expect(getStartedButton).toBeInTheDocument() await expect(byokButton).not.toBeInTheDocument() }, } export const ActiveConversation: Story = { decorators: [createStoryDecorator({ task: mockTaskHistory[0], currentTaskItem: mockTaskHistory[0] })], parameters: { docs: { description: { story: "An active conversation showing a typical interaction with AI-Hydro, including task creation, tool usage, and AI responses.", }, }, }, } export const StreamingResponse: Story = { decorators: [createStoryDecorator({ aihydroMessages: mockStreamingMessages })], parameters: { docs: { description: { story: "Shows a streaming response in progress, demonstrating real-time AI response rendering.", }, }, }, } const createLongMessages = (): AiHydroMessage[] => [ createMessage(30, "say", "task", "Help me build a complete e-commerce application with React, Node.js, and MongoDB"), createMessage( 29.7, "say", "text", "I'll help you build a complete e-commerce application. Let's start by setting up the project structure and implementing the core features step by step.", ), createMessage( 29.3, "say", "tool", JSON.stringify({ tool: "newFileCreated", path: "package.json", content: "// Package.json content..." }), ), createMessage( 29, "say", "text", "Great! I've set up the initial package.json. Now let's create the backend server with Express and MongoDB integration.", ), createMessage( 28.7, "say", "tool", JSON.stringify({ tool: "newFileCreated", path: "server.js", content: "// Express server code..." }), ), createMessage( 28.3, "say", "text", "Perfect! The backend server is set up. Now let's create the product model and routes for handling product operations.", ), createMessage( 28, "say", "tool", JSON.stringify({ tool: "newFileCreated", path: "models/Product.js", content: "// Product model code..." }), ), createMessage( 27.7, "say", "text", "Excellent! The Product model is ready with all necessary fields. Now let's create the React frontend with a modern component structure.", ), createMessage(27.3, "say", "command", "cd client && npx create-react-app . --template typescript"), createMessage(27, "say", "command_output", "Creating a new React app... Success! Created client at /path/to/project/client"), createMessage( 26.7, "say", "text", "Great! The React frontend is set up with TypeScript. Now let's create the main components for our e-commerce application.", ), ] export const LongConversation: Story = { decorators: [createStoryDecorator({ aihydroMessages: createLongMessages() })], parameters: { docs: { description: { story: "A longer conversation showing multiple tool uses, file creation, and command execution in a complex development task.", }, }, }, } // Optimized message patterns for common scenarios const createErrorMessages = () => [ createMessage(5, "say", "task", "Help me fix the build errors in my React application"), createMessage( 4.7, "say", "text", "I'll help you fix the build errors. Let me first examine the current state of your application.", ), createMessage(4.3, "say", "command", "npm run build"), createMessage(4, "say", "error", "Build failed with TypeScript errors in UserProfile.tsx and api.ts"), createMessage( 3.7, "say", "text", "I can see there are TypeScript errors in your code. Let me examine the files and fix these issues.", ), createMessage(3.3, "say", "tool", JSON.stringify({ tool: "readFile", path: "src/components/UserProfile.tsx" })), createMessage( 3, "say", "text", "I found the issue. The User type doesn't have a 'username' property. Let me fix this by updating the component to use the correct property name.", ), ] const createAskMessage = (type: string, text: string, streamingFailedMessage?: string) => ({ ts: Date.now() - 60000, type: "ask" as const, ask: type, text, streamingFailedMessage, }) export const ErrorState: Story = { decorators: [createStoryDecorator({ aihydroMessages: createErrorMessages() })], parameters: { docs: { description: { story: "Shows how AI-Hydro handles and displays error messages, helping users understand and resolve issues.", }, }, }, } export const AutoApprovalEnabled: Story = { decorators: [ createStoryDecorator({ autoApprovalSettings: { ...DEFAULT_AUTO_APPROVAL_SETTINGS, enabled: true, maxRequestsPerTask: 10, maxRequestsPerHour: 50, }, }), ], parameters: { docs: { description: { story: "Shows the interface with auto-approval enabled, allowing AI-Hydro to execute certain actions automatically without user confirmation.", }, }, }, } const createPlanModeMessages = () => [ createMessage(5, "say", "task", "Help me refactor my React application to use TypeScript and improve performance"), createApiReqMessage(4.9, "Planning analysis request", { tokensIn: 20000, tokensOut: 19500, cost: 0.065 }), createMessage( 4.7, "say", "text", "I'll help you refactor your React application to use TypeScript and improve performance. Let me create a detailed plan for this migration.", ), createApiReqMessage(4.5, "Detailed planning request", { tokensIn: 20002, tokensOut: 12500, cost: 0.095 }), createAskMessage( "plan_mode_respond", "Here's my comprehensive plan for refactoring your React application with TypeScript migration and performance optimization phases.", ), ] export const PlanMode: Story = { decorators: [ createStoryDecorator({ aihydroMessages: createPlanModeMessages(), apiConfiguration: mockApiConfigurationPlan, mode: "plan" as const, }), ], parameters: { docs: { description: { story: "Shows AI-Hydro in Plan mode, where it focuses on creating detailed plans and discussing approaches before implementation.", }, }, }, } export const EmptyState: Story = { decorators: [createStoryDecorator({ aihydroMessages: [], taskHistory: [], isNewUser: true })], parameters: { docs: { description: { story: "Shows the empty state for first-time users with no conversation history or active tasks.", }, }, }, } const createBrowserMessages = () => [ createMessage(5, "say", "task", "Help me test the login functionality on my web application"), createMessage( 4.7, "say", "text", "I'll help you test the login functionality. Let me launch a browser and navigate to your application.", ), createMessage(4.3, "say", "browser_action_launch", JSON.stringify({ action: "launch", url: "http://localhost:3000/login" })), createMessage( 4, "say", "browser_action_result", JSON.stringify({ currentUrl: "http://localhost:3000/login", logs: "Page loaded successfully" }), ), createMessage( 3.7, "say", "text", "Great! The browser has launched and navigated to your login page. Now let me test the login functionality.", ), createMessage(3.3, "say", "browser_action", JSON.stringify({ action: "click", coordinate: "400,200" })), createMessage(3, "say", "browser_action", JSON.stringify({ action: "type", text: "test@example.com" })), ] export const BrowserAutomation: Story = { decorators: [createStoryDecorator({ aihydroMessages: createBrowserMessages() })], parameters: { docs: { description: { story: "Shows AI-Hydro performing browser automation tasks, including launching browsers, clicking elements, and testing web applications.", }, }, }, } // Optimized stories using ask message pattern const createToolApprovalMessages = () => [ createMessage(5, "say", "task", "Help me read the configuration file"), createMessage(4.7, "say", "text", "I need to read a file to understand your configuration."), createAskMessage("tool", JSON.stringify({ tool: "read_file", path: "config.json" })), ] export const ToolApproval: Story = { decorators: [createStoryDecorator({ aihydroMessages: createToolApprovalMessages() })], parameters: { docs: { description: { story: "Shows tool approval request with Approve/Reject buttons for file operations.", }, }, }, } export const ToolSave: Story = { decorators: [ createStoryDecorator({ aihydroMessages: [ createMessage(5, "say", "task", "Update the README file with new instructions"), createMessage(4.7, "say", "text", "I'll update your README file with the new instructions."), createAskMessage("tool", JSON.stringify({ tool: "editedExistingFile", path: "README.md" })), ], }), ], parameters: { docs: { description: { story: "Shows file save request with Save/Reject buttons for file editing operations.", }, }, }, } // Quick story generators for common patterns const quickStory = ( name: string, askType: string, text: string, description: string, streamingFailedMessage?: string, ): Story => ({ decorators: [ createStoryDecorator({ aihydroMessages: [ ...createLongMessages(), createMessage(6, "say", "task", `Help with ${name.toLowerCase()}`), createMessage(4.7, "say", "text", `I'll help you with ${name.toLowerCase()}.`), createAskMessage(askType, text, streamingFailedMessage), ], }), ], parameters: { docs: { description: { story: description } } }, }) export const CommandExecution: Story = quickStory( "Command Execution", "command", "npm install", "Shows command execution request with Run Command/Reject buttons.", ) export const CommandOutput: Story = { decorators: [ createStoryDecorator({ aihydroMessages: [ createAskMessage("command", "npm install"), createAskMessage("command_output", "Installing packages... This may take a few minutes."), ], }), ], parameters: { docs: { description: { story: "Shows command output with Proceed While Running button during command execution.", }, }, }, } // Batch create remaining optimized stories export const ApiRequestFailed = quickStory( "API Request Failed", "api_req_failed", "API request failed due to network timeout. Would you like to retry?", "Shows error recovery options with Retry/Start New Task buttons when API requests fail.", ) export const MistakeLimitReached = quickStory( "Mistake Limit", "mistake_limit_reached", "I've made several attempts to fix this issue but haven't been successful.", "Shows mistake limit reached state with Proceed Anyways/Start New Task options.", ) export const CompletionResult = quickStory( "Task Completion", "completion_result", "Task completed successfully! I've implemented all the requested features.", "Shows task completion state with Start New Task button.", ) export const BrowserActionLaunch = quickStory( "Browser Launch", "browser_action_launch", "Launch browser to test the website at http://localhost:3000", "Shows browser action approval with Approve/Reject buttons for browser launch.", ) export const McpServerUsage = quickStory( "MCP Server", "use_mcp_server", JSON.stringify({ tool: "get_weather", location: "New York" }), "Shows MCP server usage approval with Approve/Reject buttons for external tool usage.", ) export const Followup = quickStory( "Follow-up", "followup", "What would you like me to work on next?", "Shows followup question state where AI-Hydro asks for next steps.", ) export const ResumeTask = quickStory( "Resume Task", "resume_task", "Would you like to resume the previous task?", "Shows resume task option for continuing interrupted work.", ) export const NewTaskWithContext = quickStory( "New Task", "new_task", "Start a new task with the current conversation context", "Shows new task creation with context preservation option.", ) export const AutoApprovalMaxReached = quickStory( "Auto-approval Limit", "auto_approval_max_req_reached", "Cline has auto-approved 5 API requests. Would you like to reset the count and proceed with the task?", "Shows auto-approval limit reached state with Proceed/Start New Task options.", "Cline has auto-approved 5 API requests. Would you like to reset the count and proceed with the task?", ) export const ApiRequestActive: Story = { decorators: [ createStoryDecorator({ aihydroMessages: [ createMessage(5, "say", "text", "Processing your request...", { partial: true }), createApiReqMessage(4.7, "Making API request to generate response", { partial: true }), ], }), ], parameters: { docs: { description: { story: "Shows active API request state with Cancel button available." } } }, } export const PlanModeResponse = quickStory( "Plan Mode Response", "plan_mode_respond", "Here's my detailed plan for creating a comprehensive testing strategy.", "Shows plan mode response where AI-Hydro presents a detailed plan for user approval.", ) export const CondenseConversation = quickStory( "Condense Conversation", "condense", "Would you like me to condense the conversation to improve performance?", "Shows utility action to condense conversation for better performance.", ) export const ReportBug = quickStory( "Report Bug", "report_bug", "Would you like to report this issue to help improve AI-Hydro?", "Shows utility action to report bugs to the GitHub repository.", ) export const ResumeCompletedTask = quickStory( "Resume Completed Task type", "resume_completed_task", "The previous task has been completed. Would you like to start a new task?", "Shows Start New Task option for resume completed task.", ) |