import * as React from 'react';
import { Box, Text } from '@anthropic/ink';
import {
isShutdownApproved,
isShutdownRejected,
isShutdownRequest,
type ShutdownRejectedMessage,
type ShutdownRequestMessage,
} from '../../utils/teammateMailbox.js';
type ShutdownRequestProps = {
request: ShutdownRequestMessage;
};
/**
* Renders a shutdown request with a warning-colored border.
*/
export function ShutdownRequestDisplay({ request }: ShutdownRequestProps): React.ReactNode {
return (
Shutdown request from {request.from}
{request.reason && (
Reason: {request.reason}
)}
);
}
type ShutdownRejectedProps = {
response: ShutdownRejectedMessage;
};
/**
* Renders a shutdown rejected message with a subtle (grey) border.
*/
export function ShutdownRejectedDisplay({ response }: ShutdownRejectedProps): React.ReactNode {
return (
Shutdown rejected by {response.from}
Reason: {response.reason}
Teammate is continuing to work. You may request shutdown again later.
);
}
/**
* Try to parse and render a shutdown message from raw content.
* Returns the rendered component if it's a shutdown message, null otherwise.
*/
export function tryRenderShutdownMessage(content: string): React.ReactNode | null {
const request = isShutdownRequest(content);
if (request) {
return ;
}
// Shutdown approved is handled inline by the caller — skip it here
if (isShutdownApproved(content)) {
return null;
}
const rejected = isShutdownRejected(content);
if (rejected) {
return ;
}
return null;
}
/**
* Get a brief summary text for a shutdown message.
* Used in places like the inbox queue where we want a short description.
* Returns null if the content is not a shutdown message.
*/
export function getShutdownMessageSummary(content: string): string | null {
const request = isShutdownRequest(content);
if (request) {
return `[Shutdown Request from ${request.from}]${request.reason ? ` ${request.reason}` : ''}`;
}
const approved = isShutdownApproved(content);
if (approved) {
return `[Shutdown Approved] ${approved.from} is now exiting`;
}
const rejected = isShutdownRejected(content);
if (rejected) {
return `[Shutdown Rejected] ${rejected.from}: ${rejected.reason}`;
}
return null;
}