Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions apps/agentstack-ui/src/components/MarkdownContent/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,18 @@

import { defaultUrlTransform } from 'react-markdown';

import { PLATFORM_FILE_CONTENT_URL_BASE } from '#api/a2a/constants.ts';
import { getFileIdFromFilePlatformUrl } from '#api/a2a/utils.ts';
import { getFileContentUrl } from '#modules/files/utils.ts';

export function urlTransform(value: string): string {
if (value.startsWith('data:image/')) {
return value;
}

if (value.startsWith(PLATFORM_FILE_CONTENT_URL_BASE)) {
return getFileContentUrl(getFileIdFromFilePlatformUrl(value));
}
Comment on lines +17 to +19
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To improve robustness, it's a good practice to check if a valid fileId is extracted before constructing the content URL. If value is just agentstack://, getFileIdFromFilePlatformUrl would return an empty string, leading to an invalid API call like /api/v1/files//content. Adding a check for fileId ensures we only process valid platform file URLs, falling back to the default transform for invalid ones.

  if (value.startsWith(PLATFORM_FILE_CONTENT_URL_BASE)) {
    const fileId = getFileIdFromFilePlatformUrl(value);

    if (fileId) {
      return getFileContentUrl(fileId);
    }
  }


return defaultUrlTransform(value);
}
Loading