Elffuss BraidHub

kikocis/continue public

main · 3.4 KiBRawPermalink
1import { Box, Text } from "ink";
2import React from "react";
3
4import {
5 ApiClientServiceState,
6 AuthServiceState,
7 ConfigServiceState,
8 MCPServiceState,
9 ModelServiceState,
10} from "../services/types.js";
11
12import { defaultBoxStyles } from "./styles.js";
13
14interface ServiceDebuggerProps {
15 services: {
16 auth?: AuthServiceState;
17 config?: ConfigServiceState;
18 model?: ModelServiceState;
19 mcp?: MCPServiceState;
20 apiClient?: ApiClientServiceState;
21 };
22 loading: boolean;
23 error: any;
24 allReady: boolean;
25 servicesLoading: boolean;
26 servicesError: any;
27}
28
29const ServiceDebugger: React.FC<ServiceDebuggerProps> = ({
30 services,
31 loading,
32 error,
33 allReady,
34 servicesLoading,
35 servicesError,
36}) => {
37 const getServiceStatus = (serviceName: string, service: any) => {
38 if (!service) return "❌ Not loaded";
39 if (service.error) return `❌ Error: ${service.error}`;
40 return "✅ Ready";
41 };
42
43 const getServiceDetails = (serviceName: string, service: any) => {
44 switch (serviceName) {
45 case "auth":
46 return service?.authConfig
47 ? `User: ${service.authConfig.email || "unknown"}`
48 : "No auth config";
49 case "config":
50 return service?.config ? `Agent: ${service.config.name}` : "No config";
51 case "model":
52 return service?.model ? `Model: ${service.model.name}` : "No model";
53 case "mcp":
54 return service?.mcpService
55 ? `Tools: ${service.mcpService.getTools()?.length || 0}`
56 : "No MCP service";
57 case "apiClient":
58 return service?.apiClient ? "API client ready" : "No API client";
59 default:
60 return "";
61 }
62 };
63
64 return (
65 <Box {...defaultBoxStyles("cyan")}>
66 <Text bold color="cyan">
67 🔧 Service Debug Info
68 </Text>
69 <Text> </Text>
70
71 <Text color="yellow">Overall Status:</Text>
72 <Text>Loading: {loading ? "🟡 Yes" : "✅ No"}</Text>
73 <Text>All Ready: {allReady ? "✅ Yes" : "❌ No"}</Text>
74 <Text>Services Loading: {servicesLoading ? "🟡 Yes" : "✅ No"}</Text>
75
76 {error && <Text color="red">Error: {String(error)}</Text>}
77
78 {servicesError && (
79 <Text color="red">Services Error: {String(servicesError)}</Text>
80 )}
81
82 <Text> </Text>
83 <Text color="yellow">Individual Services:</Text>
84
85 {["auth", "config", "model", "mcp", "apiClient"].map((serviceName) => {
86 const service = services[serviceName as keyof typeof services];
87 const status = getServiceStatus(serviceName, service);
88 const details = getServiceDetails(serviceName, service);
89
90 return (
91 <Box key={serviceName} flexDirection="column" marginLeft={2}>
92 <Text>
93 <Text color="white">{serviceName}:</Text> {status}
94 </Text>
95 {details && (
96 <Box marginLeft={2}>
97 <Text color="gray">{details}</Text>
98 </Box>
99 )}
100 </Box>
101 );
102 })}
103
104 <Text> </Text>
105 <Text color="yellow">Intro Message Conditions:</Text>
106 <Text>Services ready: {allReady ? "✅" : "❌"}</Text>
107 <Text>Has config: {services.config?.config ? "✅" : "❌"}</Text>
108 <Text>Has model: {services.model?.model ? "✅" : "❌"}</Text>
109 <Text>Has MCP service: {services.mcp?.mcpService ? "✅" : "❌"}</Text>
110
111 <Text> </Text>
112 <Text color="gray" italic>
113 Comment out this component when debugging is complete
114 </Text>
115 </Box>
116 );
117};
118
119export { ServiceDebugger };