pyb-ts
Version:
PYB-CLI - Minimal AI Agent with multi-model support and CLI interface
79 lines (78 loc) • 3.87 kB
JavaScript
import React from "react";
import { AssistantBashOutputMessage } from "./AssistantBashOutputMessage.js";
import { AssistantLocalCommandOutputMessage } from "./AssistantLocalCommandOutputMessage.js";
import { getTheme } from "@utils/theme";
import { Box, Text } from "ink";
import { Cost } from "@components/Cost";
import {
API_ERROR_MESSAGE_PREFIX,
CREDIT_BALANCE_TOO_LOW_ERROR_MESSAGE,
INVALID_API_KEY_ERROR_MESSAGE,
PROMPT_TOO_LONG_ERROR_MESSAGE
} from "@services/claude";
import {
CANCEL_MESSAGE,
INTERRUPT_MESSAGE,
INTERRUPT_MESSAGE_FOR_TOOL_USE,
isEmptyMessageText,
NO_RESPONSE_REQUESTED
} from "@utils/messages";
import { BLACK_CIRCLE } from "@constants/figures";
import { applyMarkdown } from "@utils/markdown";
import { useTerminalSize } from "@hooks/useTerminalSize";
function AssistantTextMessage({
param: { text },
costUSD,
durationMs,
debug,
addMargin,
shouldShowDot,
verbose
}) {
const { columns } = useTerminalSize();
if (isEmptyMessageText(text)) {
return null;
}
if (text.startsWith("<bash-stdout") || text.startsWith("<bash-stderr")) {
return /* @__PURE__ */ React.createElement(AssistantBashOutputMessage, { content: text, verbose });
}
if (text.startsWith("<local-command-stdout") || text.startsWith("<local-command-stderr")) {
return /* @__PURE__ */ React.createElement(AssistantLocalCommandOutputMessage, { content: text });
}
if (text.startsWith(API_ERROR_MESSAGE_PREFIX)) {
return /* @__PURE__ */ React.createElement(Text, null, "\xA0\xA0\uFFFD\uFFFD?\xA0", /* @__PURE__ */ React.createElement(Text, { color: getTheme().error }, text === API_ERROR_MESSAGE_PREFIX ? `${API_ERROR_MESSAGE_PREFIX}: Please wait a moment and try again.` : text));
}
switch (text) {
// Local JSX commands don't need a response, but we still want the assistant to see them
// Tool results render their own interrupt messages
case NO_RESPONSE_REQUESTED:
case INTERRUPT_MESSAGE_FOR_TOOL_USE:
return null;
case INTERRUPT_MESSAGE:
case CANCEL_MESSAGE:
return /* @__PURE__ */ React.createElement(Text, null, "\xA0\xA0\uFFFD\uFFFD?\xA0", /* @__PURE__ */ React.createElement(Text, { color: getTheme().error }, "Interrupted by user"));
case PROMPT_TOO_LONG_ERROR_MESSAGE:
return /* @__PURE__ */ React.createElement(Text, null, "\xA0\xA0\uFFFD\uFFFD?\xA0", /* @__PURE__ */ React.createElement(Text, { color: getTheme().error }, "Context low \xB7 Run /compact to compact & continue"));
case CREDIT_BALANCE_TOO_LOW_ERROR_MESSAGE:
return /* @__PURE__ */ React.createElement(Text, null, "\xA0\xA0\uFFFD\uFFFD?\xA0", /* @__PURE__ */ React.createElement(Text, { color: getTheme().error }, "Credit balance too low \xB7 Add funds: https://console.anthropic.com/settings/billing"));
case INVALID_API_KEY_ERROR_MESSAGE:
return /* @__PURE__ */ React.createElement(Text, null, "\xA0\xA0\uFFFD\uFFFD?\xA0", /* @__PURE__ */ React.createElement(Text, { color: getTheme().error }, INVALID_API_KEY_ERROR_MESSAGE));
default:
return /* @__PURE__ */ React.createElement(
Box,
{
alignItems: "flex-start",
flexDirection: "row",
justifyContent: "space-between",
marginTop: addMargin ? 1 : 0,
width: "100%"
},
/* @__PURE__ */ React.createElement(Box, { flexDirection: "row" }, shouldShowDot && /* @__PURE__ */ React.createElement(Box, { minWidth: 2 }, /* @__PURE__ */ React.createElement(Text, { color: getTheme().text }, BLACK_CIRCLE)), /* @__PURE__ */ React.createElement(Box, { flexDirection: "column", width: columns - 6 }, /* @__PURE__ */ React.createElement(Text, null, applyMarkdown(text)))),
/* @__PURE__ */ React.createElement(Cost, { costUSD, durationMs, debug })
);
}
}
export {
AssistantTextMessage
};
//# sourceMappingURL=AssistantTextMessage.js.map