slashCommandPanelSections.tsx 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. import { useMemo } from "react";
  2. import type { IntlInstance } from "@/i18n/IntlProvider.js";
  3. import type { PromptInputSuggestionItem } from "@/lib/promptInputTriggers.js";
  4. import {
  5. type MentionPanelOption,
  6. type MentionPanelSection,
  7. } from "@/mentions/components/MentionPanel.js";
  8. export function useSlashCommandMentionPanelSections(
  9. intl: IntlInstance,
  10. commandsLength: number,
  11. filteredCommandSuggestions: PromptInputSuggestionItem[],
  12. filteredSkillSuggestions: PromptInputSuggestionItem[],
  13. skillsLoading: boolean,
  14. skillsError: string | null,
  15. filteredSubagentSuggestions: PromptInputSuggestionItem[],
  16. subagentsLoading: boolean,
  17. subagentsError: string | null,
  18. ): MentionPanelSection[] {
  19. return useMemo(
  20. () => [
  21. {
  22. id: "commands",
  23. title: intl.formatMessage({ id: "chat.slash.commands.title" }),
  24. options: filteredCommandSuggestions.map<MentionPanelOption>((suggestion) => ({
  25. id: suggestion.id,
  26. label: `/${suggestion.value}`,
  27. description: suggestion.description,
  28. content: (
  29. <span className="min-w-0 flex-1 flex items-center gap-2">
  30. <span className="truncate text-ui-base font-medium text-foreground max-w-[40%]">
  31. {`/${suggestion.value}`}
  32. </span>
  33. <span className="truncate text-ui-base text-foreground-subtlest flex-1">
  34. {suggestion.description}
  35. </span>
  36. </span>
  37. ),
  38. })),
  39. loading: false,
  40. emptyText:
  41. commandsLength === 0
  42. ? intl.formatMessage({ id: "chat.slash.emptyUnavailable" })
  43. : intl.formatMessage({ id: "chat.slash.emptyResults" }),
  44. },
  45. {
  46. id: "skills",
  47. title: intl.formatMessage({ id: "chat.slash.skills.title" }),
  48. options: filteredSkillSuggestions.map<MentionPanelOption>((suggestion) => ({
  49. id: suggestion.id,
  50. label: `$${suggestion.value}`,
  51. description: suggestion.description,
  52. content: (
  53. <span className="min-w-0 flex-1 flex items-center gap-2">
  54. <span className="truncate text-ui-base font-medium text-foreground max-w-[40%]">
  55. {`$${suggestion.value}`}
  56. </span>
  57. <span className="truncate text-ui-base text-foreground-subtlest flex-1">
  58. {suggestion.description}
  59. </span>
  60. </span>
  61. ),
  62. })),
  63. loading: skillsLoading,
  64. loadingText: intl.formatMessage({ id: "chat.mention.category.loading" }),
  65. emptyText: intl.formatMessage({ id: "chat.slash.skills.empty" }),
  66. errorText: skillsError,
  67. },
  68. {
  69. id: "subagents",
  70. title: intl.formatMessage({ id: "chat.slash.subagents.title" }),
  71. options: filteredSubagentSuggestions.map<MentionPanelOption>((suggestion) => ({
  72. id: suggestion.id,
  73. label: suggestion.value,
  74. description: suggestion.description,
  75. content: (
  76. <span className="min-w-0 flex-1 flex items-center gap-2">
  77. <span className="truncate text-ui-base font-medium text-foreground max-w-[40%]">
  78. {suggestion.value}
  79. </span>
  80. <span className="truncate text-ui-base text-foreground-subtlest flex-1">
  81. {suggestion.description}
  82. </span>
  83. </span>
  84. ),
  85. })),
  86. loading: subagentsLoading,
  87. emptyText: intl.formatMessage({ id: "chat.slash.subagents.empty" }),
  88. errorText: subagentsError,
  89. },
  90. ],
  91. [
  92. commandsLength,
  93. filteredCommandSuggestions,
  94. filteredSkillSuggestions,
  95. filteredSubagentSuggestions,
  96. intl,
  97. skillsError,
  98. skillsLoading,
  99. subagentsError,
  100. subagentsLoading,
  101. ],
  102. );
  103. }