metadataUtils.js 843 B

12345678910111213141516171819202122
  1. /**
  2. * Utilities for working with BaseMetadata objects.
  3. */
  4. /**
  5. * Gets the display name for an object with BaseMetadata.
  6. * For tools, the precedence is: title → annotations.title → name
  7. * For other objects: title → name
  8. * This implements the spec requirement: "if no title is provided, name should be used for display purposes"
  9. */
  10. export function getDisplayName(metadata) {
  11. // First check for title (not undefined and not empty string)
  12. if (metadata.title !== undefined && metadata.title !== '') {
  13. return metadata.title;
  14. }
  15. // Then check for annotations.title (only present in Tool objects)
  16. if ('annotations' in metadata && metadata.annotations?.title) {
  17. return metadata.annotations.title;
  18. }
  19. // Finally fall back to name
  20. return metadata.name;
  21. }
  22. //# sourceMappingURL=metadataUtils.js.map