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