You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

118 lines
4.0 KiB

11 months ago
10 months ago
11 months ago
10 months ago
11 months ago
10 months ago
11 months ago
  1. import { useEffect, useRef, useState } from "react";
  2. import { Tooltip } from "react-tooltip";
  3. import { At } from "@phosphor-icons/react";
  4. import { useIsAgentSessionActive } from "@/utils/chat/agent";
  5. export default function AvailableAgentsButton({ showing, setShowAgents }) {
  6. const agentSessionActive = useIsAgentSessionActive();
  7. if (agentSessionActive) return null;
  8. return (
  9. <div
  10. id="agent-list-btn"
  11. data-tooltip-id="tooltip-agent-list-btn"
  12. data-tooltip-content="查看可用于聊天的所有可用座席."
  13. aria-label="查看可用于聊天的所有可用座席."
  14. onClick={() => setShowAgents(!showing)}
  15. className={`flex justify-center items-center cursor-pointer ${
  16. showing ? "!opacity-100" : ""
  17. }`}
  18. >
  19. <At
  20. color="var(--theme-sidebar-footer-icon-fill)"
  21. className={`w-[22px] h-[22px] pointer-events-none text-theme-text-primary opacity-60 hover:opacity-100 light:opacity-100 light:hover:opacity-60`}
  22. />
  23. <Tooltip
  24. id="tooltip-agent-list-btn"
  25. place="top"
  26. delayShow={300}
  27. className="tooltip !text-xs z-99"
  28. />
  29. </div>
  30. );
  31. }
  32. function AbilityTag({ text }) {
  33. return (
  34. <div className="px-2 bg-theme-action-menu-item-hover text-theme-text-secondary text-xs w-fit rounded-sm">
  35. <p>{text}</p>
  36. </div>
  37. );
  38. }
  39. export function AvailableAgents({
  40. showing,
  41. setShowing,
  42. sendCommand,
  43. promptRef,
  44. }) {
  45. const formRef = useRef(null);
  46. const agentSessionActive = useIsAgentSessionActive();
  47. useEffect(() => {
  48. function listenForOutsideClick() {
  49. if (!showing || !formRef.current) return false;
  50. document.addEventListener("click", closeIfOutside);
  51. }
  52. listenForOutsideClick();
  53. }, [showing, formRef.current]);
  54. const closeIfOutside = ({ target }) => {
  55. if (target.id === "agent-list-btn") return;
  56. const isOutside = !formRef?.current?.contains(target);
  57. if (!isOutside) return;
  58. setShowing(false);
  59. };
  60. if (agentSessionActive) return null;
  61. return (
  62. <>
  63. <div hidden={!showing}>
  64. <div className="w-full flex justify-center absolute bottom-[130px] md:bottom-[150px] left-0 z-10 px-4">
  65. <div
  66. ref={formRef}
  67. className="w-[600px] p-2 bg-theme-action-menu-bg rounded-2xl shadow flex-col justify-center items-start gap-2.5 inline-flex"
  68. >
  69. <button
  70. onClick={() => {
  71. setShowing(false);
  72. sendCommand("@agent ", false);
  73. promptRef?.current?.focus();
  74. }}
  75. className="border-none w-full hover:cursor-pointer hover:bg-theme-action-menu-item-hover px-2 py-2 rounded-xl flex flex-col justify-start group"
  76. >
  77. <div className="w-full flex-col text-left flex pointer-events-none">
  78. <div className="text-theme-text-primary text-sm">
  79. <b>@代理</b> - 此工作区的默认代理.
  80. </div>
  81. <div className="flex flex-wrap gap-2 mt-2">
  82. <AbilityTag text="rag-search" />
  83. <AbilityTag text="web-scraping" />
  84. <AbilityTag text="web-browsing" />
  85. <AbilityTag text="save-file-to-browser" />
  86. <AbilityTag text="list-documents" />
  87. <AbilityTag text="summarize-document" />
  88. <AbilityTag text="chart-generation" />
  89. </div>
  90. </div>
  91. </button>
  92. <button
  93. type="button"
  94. disabled={true}
  95. className="w-full rounded-xl flex flex-col justify-start group"
  96. >
  97. <div className="w-full flex-col text-center flex pointer-events-none">
  98. <div className="text-theme-text-secondary text-xs italic">
  99. 海关代理很快就要来了
  100. </div>
  101. </div>
  102. </button>
  103. </div>
  104. </div>
  105. </div>
  106. </>
  107. );
  108. }
  109. export function useAvailableAgents() {
  110. const [showAgents, setShowAgents] = useState(false);
  111. return { showAgents, setShowAgents };
  112. }