|
| 1 | +import { ExtensionStateContextType, ExtensionStateContext } from "../src/context/ExtensionStateContext" |
| 2 | +import { McpServer } from "../../src/shared/mcp" |
| 3 | +import { ApiConfiguration, ModelInfo } from "../../src/shared/api" |
| 4 | +import { HistoryItem } from "../../src/shared/HistoryItem" // Import HistoryItem |
| 5 | +import { useContext } from "react" |
| 6 | + |
| 7 | +// Mock ModelInfo |
| 8 | +const mockModelInfo: ModelInfo = { |
| 9 | + contextWindow: 2048, |
| 10 | + supportsImages: true, |
| 11 | + supportsPromptCache: true, |
| 12 | + reasoningEffort: "low", |
| 13 | +} |
| 14 | + |
| 15 | +// Mock API configuration |
| 16 | +const mockApiConfig: ApiConfiguration = { |
| 17 | + apiModelId: "mock-model", |
| 18 | + glamaModelInfo: mockModelInfo, |
| 19 | +} |
| 20 | + |
| 21 | +// Mock MCP server |
| 22 | +const mockMcpServer: McpServer = { |
| 23 | + name: "mock-server", |
| 24 | + tools: [], |
| 25 | + resources: [], |
| 26 | + resourceTemplates: [], |
| 27 | + disabled: false, |
| 28 | + config: "?", |
| 29 | + status: "disconnected", |
| 30 | +} |
| 31 | + |
| 32 | +// Mock task history item (Corrected to match HistoryItem type) |
| 33 | +const mockTaskHistoryItem: HistoryItem = { |
| 34 | + id: "mock-task-id", |
| 35 | + ts: Date.now(), |
| 36 | + task: "Sample task", |
| 37 | + tokensIn: 100, |
| 38 | + tokensOut: 200, |
| 39 | + totalCost: 0.5, |
| 40 | +} |
| 41 | + |
| 42 | +// Mock file paths and opened tabs (more realistic mock data) |
| 43 | +const mockFilePaths: string[] = [ |
| 44 | + "/Roo-Code/src/components/chat/ChatTextArea.tsx", |
| 45 | + "/Roo-Code/src/components/common/CodeBlock.tsx", |
| 46 | + "/Roo-Code/webview-ui/.storybook/preview-context.tsx", |
| 47 | +] |
| 48 | +const mockOpenedTabs: Array<{ label: string; isActive: boolean; path?: string }> = [ |
| 49 | + { label: "ChatTextArea.tsx", isActive: true, path: "/Roo-Code/src/components/chat/ChatTextArea.tsx" }, |
| 50 | + { label: "CodeBlock.tsx", isActive: false, path: "/Roo-Code/src/components/common/CodeBlock.tsx" }, |
| 51 | +] |
| 52 | + |
| 53 | +const defaultContext: ExtensionStateContextType = { |
| 54 | + // Version and state |
| 55 | + version: "1.0.0", |
| 56 | + didHydrateState: true, |
| 57 | + showWelcome: false, |
| 58 | + |
| 59 | + // Messages and history |
| 60 | + clineMessages: [], |
| 61 | + taskHistory: [mockTaskHistoryItem], |
| 62 | + shouldShowAnnouncement: false, |
| 63 | + |
| 64 | + // API and models |
| 65 | + apiConfiguration: mockApiConfig, |
| 66 | + glamaModels: {}, |
| 67 | + requestyModels: {}, |
| 68 | + openRouterModels: {}, |
| 69 | + unboundModels: {}, |
| 70 | + openAiModels: [], |
| 71 | + |
| 72 | + // MCP |
| 73 | + mcpServers: [mockMcpServer], |
| 74 | + mcpEnabled: true, |
| 75 | + enableMcpServerCreation: true, |
| 76 | + |
| 77 | + // Files and tabs |
| 78 | + filePaths: mockFilePaths, |
| 79 | + openedTabs: mockOpenedTabs, |
| 80 | + currentCheckpoint: undefined, |
| 81 | + |
| 82 | + // Settings |
| 83 | + mode: "code", |
| 84 | + preferredLanguage: "English", |
| 85 | + requestDelaySeconds: 0, |
| 86 | + rateLimitSeconds: 0, |
| 87 | + writeDelayMs: 0, |
| 88 | + browserViewportSize: "1200x800", |
| 89 | + screenshotQuality: 75, |
| 90 | + terminalOutputLineLimit: 500, |
| 91 | + fuzzyMatchThreshold: 1.0, |
| 92 | + maxOpenTabsContext: 20, |
| 93 | + |
| 94 | + // Features |
| 95 | + diffEnabled: false, |
| 96 | + checkpointsEnabled: false, |
| 97 | + soundEnabled: false, |
| 98 | + soundVolume: 0.5, |
| 99 | + autoApprovalEnabled: true, |
| 100 | + |
| 101 | + // Permissions |
| 102 | + alwaysAllowBrowser: true, |
| 103 | + alwaysAllowExecute: true, |
| 104 | + alwaysAllowMcp: true, |
| 105 | + alwaysAllowModeSwitch: true, |
| 106 | + alwaysAllowReadOnly: true, |
| 107 | + alwaysApproveResubmit: true, |
| 108 | + alwaysAllowWrite: true, |
| 109 | + allowedCommands: [], |
| 110 | + |
| 111 | + // Other state |
| 112 | + customModePrompts: {}, |
| 113 | + customSupportPrompts: {}, |
| 114 | + experiments: { |
| 115 | + experimentalDiffStrategy: false, |
| 116 | + search_and_replace: false, |
| 117 | + insert_content: false, |
| 118 | + powerSteering: false, |
| 119 | + }, |
| 120 | + customModes: [], |
| 121 | + enhancementApiConfigId: undefined, |
| 122 | + currentApiConfigName: "default", |
| 123 | + listApiConfigMeta: [], |
| 124 | + theme: {}, |
| 125 | + |
| 126 | + // Setters |
| 127 | + setApiConfiguration: () => {}, |
| 128 | + setCustomInstructions: () => {}, |
| 129 | + setAlwaysAllowReadOnly: () => {}, |
| 130 | + setAlwaysAllowWrite: () => {}, |
| 131 | + setAlwaysAllowExecute: () => {}, |
| 132 | + setAlwaysAllowBrowser: () => {}, |
| 133 | + setAlwaysAllowMcp: () => {}, |
| 134 | + setAlwaysAllowModeSwitch: () => {}, |
| 135 | + setShowAnnouncement: () => {}, |
| 136 | + setAllowedCommands: () => {}, |
| 137 | + setSoundEnabled: () => {}, |
| 138 | + setSoundVolume: () => {}, |
| 139 | + setDiffEnabled: () => {}, |
| 140 | + setCheckpointsEnabled: () => {}, |
| 141 | + setBrowserViewportSize: () => {}, |
| 142 | + setFuzzyMatchThreshold: () => {}, |
| 143 | + setPreferredLanguage: () => {}, |
| 144 | + setWriteDelayMs: () => {}, |
| 145 | + setScreenshotQuality: () => {}, |
| 146 | + setTerminalOutputLineLimit: () => {}, |
| 147 | + setMcpEnabled: () => {}, |
| 148 | + setEnableMcpServerCreation: () => {}, |
| 149 | + setAlwaysApproveResubmit: () => {}, |
| 150 | + setRequestDelaySeconds: () => {}, |
| 151 | + setRateLimitSeconds: () => {}, |
| 152 | + setCurrentApiConfigName: () => {}, |
| 153 | + setListApiConfigMeta: () => {}, |
| 154 | + onUpdateApiConfig: () => {}, |
| 155 | + setMode: () => {}, |
| 156 | + setCustomModePrompts: () => {}, |
| 157 | + setCustomSupportPrompts: () => {}, |
| 158 | + setEnhancementApiConfigId: () => {}, |
| 159 | + setExperimentEnabled: () => {}, |
| 160 | + setAutoApprovalEnabled: () => {}, |
| 161 | + setCustomModes: () => {}, |
| 162 | + setMaxOpenTabsContext: () => {}, |
| 163 | +} |
| 164 | + |
| 165 | +export const PreviewExtensionStateContextProvider: React.FC<{ children: React.ReactNode }> = ({ children }) => { |
| 166 | + console.log("PreviewExtensionStateContextProvider is rendering!") // Re-add console log |
| 167 | + console.log("Context Value:", defaultContext) // Log context value |
| 168 | + return <ExtensionStateContext.Provider value={defaultContext}>{children}</ExtensionStateContext.Provider> |
| 169 | +} |
| 170 | + |
| 171 | +export const usePreviewExtensionState = () => { |
| 172 | + const context = useContext(ExtensionStateContext) |
| 173 | + console.log("useExtensionState Hook Context:", context) // Log context in hook |
| 174 | + return context |
| 175 | +} |
0 commit comments