summaryrefslogtreecommitdiff
path: root/packages/cli/src/ui/components/messages/ToolGroupMessage.tsx
blob: 0662e333a4c36f8562587d269f4ef1fb4601d072 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/**
 * @license
 * Copyright 2025 Google LLC
 * SPDX-License-Identifier: Apache-2.0
 */

import React from 'react';
import { Box } from 'ink';
import { IndividualToolCallDisplay, ToolCallStatus } from '../../types.js';
import { ToolMessage } from './ToolMessage.js';
import { PartListUnion } from '@google/genai';
import { ToolConfirmationMessage } from './ToolConfirmationMessage.js';

interface ToolGroupMessageProps {
  toolCalls: IndividualToolCallDisplay[];
  onSubmit: (value: PartListUnion) => void;
}

// Main component renders the border and maps the tools using ToolMessage
export const ToolGroupMessage: React.FC<ToolGroupMessageProps> = ({
  toolCalls,
  onSubmit,
}) => {
  const hasPending = toolCalls.some((t) => t.status === ToolCallStatus.Pending);
  const borderColor = hasPending ? 'yellow' : 'blue';

  return (
    <Box flexDirection="column" borderStyle="round" borderColor={borderColor}>
      {toolCalls.map((tool) => (
        <React.Fragment key={tool.callId}>
          <ToolMessage
            key={tool.callId} // Use callId as the key
            callId={tool.callId} // Pass callId
            name={tool.name}
            description={tool.description}
            resultDisplay={tool.resultDisplay}
            status={tool.status}
            confirmationDetails={tool.confirmationDetails} // Pass confirmationDetails
          />
          {tool.status === ToolCallStatus.Confirming &&
            tool.confirmationDetails && (
              <ToolConfirmationMessage
                confirmationDetails={tool.confirmationDetails}
                onSubmit={onSubmit}
              ></ToolConfirmationMessage>
            )}
        </React.Fragment>
      ))}
      {/* Optional: Add padding below the last item if needed,
                though ToolMessage already has some vertical space implicitly */}
      {/* {tools.length > 0 && <Box height={1} />} */}
    </Box>
  );
};