refactor(parsers): change uiResources to a constant and streamline artifacts handling

This commit is contained in:
Marco Beretta 2025-10-28 22:49:05 +01:00
parent 9ce9d404d7
commit b9abe5d77e
No known key found for this signature in database
GPG key ID: D918033D8E74CC11

View file

@ -106,7 +106,7 @@ export function formatToolContent(
const formattedContent: t.FormattedContent[] = [];
const imageUrls: t.FormattedContent[] = [];
let currentTextBlock = '';
let uiResources: t.UIResource[] = [];
const uiResources: UIResource[] = [];
type ContentHandler = undefined | ((item: t.ToolContentPart) => void);
@ -176,11 +176,17 @@ export function formatToolContent(
formattedContent.push({ type: 'text', text: currentTextBlock });
}
let artifacts: t.Artifacts = imageUrls.length ? { content: imageUrls } : undefined;
if (uiResources.length) {
formattedContent.push({ type: 'text', metadata: 'ui_resources', text: btoa(JSON.stringify(uiResources))});
artifacts = {
...artifacts,
[Tools.ui_resources]: {
data: uiResources,
},
};
}
const artifacts = imageUrls.length ? { content: imageUrls } : undefined;
if (CONTENT_ARRAY_PROVIDERS.has(provider)) {
return [formattedContent, artifacts];
}