| 1 | import { AssistantUnrolled, ModelConfig } from "@continuedev/config-yaml"; |
| 2 | import { Box, Text } from "ink"; |
| 3 | import React, { useMemo } from "react"; |
| 4 | |
| 5 | import { MCPService } from "../services/MCPService.js"; |
| 6 | import { isModelCapable } from "../utils/modelCapability.js"; |
| 7 | |
| 8 | import { ModelCapabilityWarning } from "./ModelCapabilityWarning.js"; |
| 9 | |
| 10 | interface IntroMessageProps { |
| 11 | config: AssistantUnrolled; |
| 12 | model: ModelConfig; |
| 13 | mcpService: MCPService; |
| 14 | } |
| 15 | |
| 16 | const 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 = isModelCapable( |
| 36 | model.provider, |
| 37 | model.name, |
| 38 | model.model, |
| 39 | ); |
| 40 | |
| 41 | return { allRules, modelCapable }; |
| 42 | }, [config.rules, model.provider, model.name, model.model]); |
| 43 | |
| 44 | return ( |
| 45 | <Box flexDirection="column" paddingX={1} paddingY={1}> |
| 46 | {/* Agent name */} |
| 47 | <Text color="blue"> |
| 48 | <Text bold>Agent:</Text> <Text color="white">{config.name}</Text> |
| 49 | </Text> |
| 50 | |
| 51 | {/* Model */} |
| 52 | <Text color="blue"> |
| 53 | <Text bold>Model:</Text>{" "} |
| 54 | <Text color="white">{model.name.split("/").pop()}</Text> |
| 55 | </Text> |
| 56 | |
| 57 | <Text> </Text> |
| 58 | |
| 59 | {/* Model capability warning */} |
| 60 | {!modelCapable && ( |
| 61 | <> |
| 62 | <ModelCapabilityWarning |
| 63 | modelName={model.name.split("/").pop() || model.name} |
| 64 | /> |
| 65 | <Text> </Text> |
| 66 | </> |
| 67 | )} |
| 68 | |
| 69 | {/* MCP prompts */} |
| 70 | {mcpPrompts.length > 0 && ( |
| 71 | <> |
| 72 | {mcpPrompts.map((prompt, index) => ( |
| 73 | <Text key={`mcp-${index}`}> |
| 74 | - <Text color="white">/{prompt.name}</Text>:{" "} |
| 75 | <Text color="gray">{prompt.description}</Text> |
| 76 | </Text> |
| 77 | ))} |
| 78 | <Text> </Text> |
| 79 | </> |
| 80 | )} |
| 81 | |
| 82 | {/* Rules */} |
| 83 | {allRules.length > 0 && ( |
| 84 | <> |
| 85 | <Text bold color="blue"> |
| 86 | Rules: |
| 87 | </Text> |
| 88 | {allRules.map((rule, index) => ( |
| 89 | <Text key={index}> |
| 90 | - <Text color="white">{rule}</Text> |
| 91 | </Text> |
| 92 | ))} |
| 93 | <Text> </Text> |
| 94 | </> |
| 95 | )} |
| 96 | |
| 97 | {/* MCP Servers */} |
| 98 | {config.mcpServers?.length && ( |
| 99 | <> |
| 100 | <Text bold color="blue"> |
| 101 | MCP Servers: |
| 102 | </Text> |
| 103 | {config.mcpServers.map((server: any, index: number) => ( |
| 104 | <Text key={index}> |
| 105 | - <Text color="white">{server?.name}</Text> |
| 106 | </Text> |
| 107 | ))} |
| 108 | <Text> </Text> |
| 109 | </> |
| 110 | )} |
| 111 | </Box> |
| 112 | ); |
| 113 | }; |
| 114 | |
| 115 | export { IntroMessage }; |