import { SparkCopyLine, SparkReplaceLine } from "@agentscope-ai/icons";
import { IAgentScopeRuntimeResponse } from "../types";
import AgentScopeRuntimeResponseBuilder from "./Builder";
import { Bubble } from "@agentscope-ai/chat";
import { Tooltip } from "@agentscope-ai/design";
import { copy } from "../../../../Util/copy";
import compact from 'lodash/compact';
import { emit } from "../../Context/useChatAnywhereEventEmitter";
import { useChatAnywhereOptions } from "../../Context/ChatAnywhereOptionsContext";
import { useTranslation } from "../../Context/ChatAnywhereI18nContext";
import React from "react";
function Usage(props: {
input_tokens: string;
output_tokens: string;
}) {
if (!props.input_tokens || !props.output_tokens) return null;
return
}
export default function Tools(props: {
data: IAgentScopeRuntimeResponse
isLast?: boolean;
}) {
const { t } = useTranslation();
const actionsOptionsList = useChatAnywhereOptions(v => v.actions?.list) || [
{
icon: ,
onClick: () => {
copy(JSON.stringify(props.data));
}
}
];
const replace = useChatAnywhereOptions(v => v.actions?.replace) ?? true;
const rightOption = useChatAnywhereOptions(v => v.actions?.right);
const actions = compact([
...actionsOptionsList.map(i => {
const res = { ...i } as any;
if (i.render) {
res.children = React.createElement(i.render, { data: props });
}
return {
...res, onClick() {
i.onClick?.(props);
}
}
}),
replace && props.isLast ? {
icon: ,
onClick: () => {
emit({
type: 'handleReplace',
data: props,
})
}
} : null,
]);
let rightNode: React.ReactElement | null;
if (rightOption === false || (Array.isArray(rightOption) && rightOption.length === 0)) {
rightNode = null;
} else if (Array.isArray(rightOption)) {
const rightActions = rightOption.map(i => {
const res = { ...i } as any;
if (i.render) {
res.children = React.createElement(i.render, { data: props.data });
}
return { ...res, onClick: () => { i.onClick?.({ data: props.data }); } };
});
rightNode = ;
} else {
rightNode = ;
}
if (!AgentScopeRuntimeResponseBuilder.maybeDone(props.data)) return null;
return }
right={rightNode}
/>
}