ModelTrajectoryExpansionMenu.tsx 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import { Settings2Icon } from "lucide-react";
  2. import { Button } from "@/components/ui/button.js";
  3. import {
  4. DropdownMenu,
  5. DropdownMenuContent,
  6. DropdownMenuItem,
  7. DropdownMenuTrigger,
  8. } from "@/components/ui/dropdown-menu.js";
  9. import { Switch } from "@/components/ui/switch.js";
  10. import type { IntlShape } from "@/ModelTrajectoryPaneParts.js";
  11. import {
  12. TRAJECTORY_EXPANSION_KINDS,
  13. type TrajectoryExpansionCommands,
  14. } from "@/ModelTrajectoryExpansion.js";
  15. import type { TrajectoryVisualRole } from "@/ModelTrajectoryRoleStyles.js";
  16. export function ModelTrajectoryExpansionMenu({
  17. commands,
  18. onToggle,
  19. intl,
  20. }: {
  21. commands: TrajectoryExpansionCommands;
  22. onToggle: (kind: TrajectoryVisualRole) => void;
  23. intl: IntlShape;
  24. }) {
  25. const label = intl.formatMessage({ id: "modelTrajectory.customExpansion" });
  26. return (
  27. <DropdownMenu>
  28. <DropdownMenuTrigger asChild>
  29. <Button
  30. data-trajectory-custom-expansion=""
  31. type="button"
  32. variant="ghost"
  33. size="icon-sm"
  34. className="shrink-0 text-foreground"
  35. aria-label={label}
  36. title={label}
  37. >
  38. <Settings2Icon className="size-3.5" />
  39. </Button>
  40. </DropdownMenuTrigger>
  41. <DropdownMenuContent align="end" className="w-52">
  42. {TRAJECTORY_EXPANSION_KINDS.map((kind) => (
  43. <DropdownMenuItem
  44. key={kind}
  45. data-trajectory-expansion-kind={kind}
  46. className="justify-between"
  47. onSelect={(event) => {
  48. event.preventDefault();
  49. onToggle(kind);
  50. }}
  51. >
  52. <span>{expansionKindLabel(kind, intl)}</span>
  53. <Switch
  54. size="sm"
  55. checked={commands[kind].expanded}
  56. className="pointer-events-none"
  57. aria-hidden="true"
  58. tabIndex={-1}
  59. />
  60. </DropdownMenuItem>
  61. ))}
  62. </DropdownMenuContent>
  63. </DropdownMenu>
  64. );
  65. }
  66. function expansionKindLabel(kind: TrajectoryVisualRole, intl: IntlShape): string {
  67. switch (kind) {
  68. case "system":
  69. case "user":
  70. case "assistant":
  71. return intl.formatMessage({ id: `modelTrajectory.role.${kind}` });
  72. case "reasoning":
  73. return intl.formatMessage({ id: "modelTrajectory.reasoning" });
  74. case "tool-call":
  75. return intl.formatMessage({ id: "modelTrajectory.toolCall" });
  76. case "tool-result":
  77. return intl.formatMessage({ id: "modelTrajectory.role.tool" });
  78. }
  79. }