Elffuss BraidHub

kikocis/continue public

86e71fea71da · 3.5 KiBRawPermalink
1import { AssistantUnrolled, ModelConfig } from "@continuedev/config-yaml";
2import { Box, Text } from "ink";
3import React, { useMemo } from "react";
4
5import { getDisplayableAsciiArt } from "../asciiArt.js";
6import { MCPService } from "../services/MCPService.js";
7import { isModelCapable } from "../utils/modelCapability.js";
8
9import { ModelCapabilityWarning } from "./ModelCapabilityWarning.js";
10
11interface IntroMessageProps {
12 config?: AssistantUnrolled;
13 model?: ModelConfig;
14 mcpService?: MCPService;
15}
16
17const IntroMessage: React.FC<IntroMessageProps> = ({
18 config,
19 model,
20 mcpService,
21}) => {
22 // Get MCP prompts directly (not memoized since they can change after first render)
23 const mcpPrompts = mcpService?.getState().prompts ?? [];
24
25 // Memoize expensive operations to avoid running on every resize
26 const { allRules, modelCapable } = useMemo(() => {
27 // Show all rules from config (command-line rules are already merged into config)
28 const configRules =
29 config?.rules?.map((rule: any) =>
30 typeof rule === "string" ? rule : rule?.name || "Unknown",
31 ) || [];
32
33 const allRules = configRules;
34
35 // Check if model is capable - now checking both name and model properties
36 const modelCapable = model
37 ? isModelCapable(model.provider, model.name, model.model)
38 : true; // Default to true if model not loaded yet
39
40 return { allRules, modelCapable };
41 }, [config?.rules, model?.provider, model?.name, model?.model]);
42
43 return (
44 <Box flexDirection="column" paddingX={1} paddingY={1}>
45 {/* ASCII Art */}
46 <Text>{getDisplayableAsciiArt()}</Text>
47 <Text> </Text>
48
49 {/* Agent name */}
50 {config && (
51 <Text color="blue">
52 <Text bold>Agent:</Text> <Text color="white">{config.name}</Text>
53 </Text>
54 )}
55
56 {/* Model */}
57 {model ? (
58 <Text color="blue">
59 <Text bold>Model:</Text>{" "}
60 <Text color="white">{model.name.split("/").pop()}</Text>
61 </Text>
62 ) : (
63 <Text color="blue">
64 <Text bold>Model:</Text> <Text color="gray">Loading...</Text>
65 </Text>
66 )}
67
68 <Text> </Text>
69
70 {/* Model capability warning */}
71 {model && !modelCapable && (
72 <>
73 <ModelCapabilityWarning
74 modelName={model.name.split("/").pop() || model.name}
75 />
76 <Text> </Text>
77 </>
78 )}
79
80 {/* MCP prompts */}
81 {mcpPrompts.length > 0 && (
82 <>
83 {mcpPrompts.map((prompt, index) => (
84 <Text key={`mcp-${index}`}>
85 - <Text color="white">/{prompt.name}</Text>:{" "}
86 <Text color="gray">{prompt.description}</Text>
87 </Text>
88 ))}
89 <Text> </Text>
90 </>
91 )}
92
93 {/* Rules */}
94 {allRules.length > 0 && (
95 <>
96 <Text bold color="blue">
97 Rules:
98 </Text>
99 {allRules.map((rule, index) => (
100 <Text key={index}>
101 - <Text color="white">{rule}</Text>
102 </Text>
103 ))}
104 <Text> </Text>
105 </>
106 )}
107
108 {/* MCP Servers */}
109 {(config?.mcpServers?.length ?? 0) > 0 && (
110 <>
111 <Text bold color="blue">
112 MCP Servers:
113 </Text>
114 {config?.mcpServers?.map((server: any, index: number) => (
115 <Text key={index}>
116 - <Text color="white">{server?.name}</Text>
117 </Text>
118 ))}
119 <Text> </Text>
120 </>
121 )}
122 </Box>
123 );
124};
125
126export { IntroMessage };