InteractionRequestOriginBadge.tsx 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import type { ZCodeInteractionRequestOrigin } from "@zcode/shared";
  2. import { cn } from "@/components/lib/utils.js";
  3. import { Badge } from "@/components/ui/badge.js";
  4. import { useZCodeIntl } from "@/i18n/IntlProvider.js";
  5. export function InteractionRequestOriginBadge({
  6. className,
  7. origin,
  8. }: {
  9. className?: string;
  10. origin?: ZCodeInteractionRequestOrigin;
  11. }) {
  12. const { intl } = useZCodeIntl();
  13. if (origin?.kind !== "subagent") {
  14. return null;
  15. }
  16. // description 点名是哪个子代理在问(动态工作流子代理为 `<名字> (<siteId>@<ordinal>)`,
  17. // docs/dynamic-workflow/launch.md「Permissions inside a run」);徽标截断,完整文本留在 tooltip。
  18. const description = origin.description?.trim();
  19. const label = description
  20. ? intl.formatMessage({ id: "chat.interactionOrigin.subagent.named" }, { description })
  21. : intl.formatMessage({ id: "chat.interactionOrigin.subagent" });
  22. const title = !origin.agentType
  23. ? label
  24. : description
  25. ? intl.formatMessage(
  26. { id: "chat.interactionOrigin.subagent.titleNamed" },
  27. { agentType: origin.agentType, description },
  28. )
  29. : intl.formatMessage(
  30. { id: "chat.interactionOrigin.subagent.title" },
  31. { agentType: origin.agentType },
  32. );
  33. return (
  34. <Badge
  35. variant="outline"
  36. title={title}
  37. data-interaction-origin-badge="subagent"
  38. className={cn("max-w-40 align-baseline text-ui-base truncate", className)}
  39. >
  40. {label}
  41. </Badge>
  42. );
  43. }