Elffuss BraidHub

kikocis/continue public

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