refactor: un-hardcode file urls
This commit is contained in:
+5
-2
@@ -3,6 +3,7 @@ import { ToolCallType } from "~~/drizzle/schema";
|
||||
import { Err, Ok, type Result } from "~~/types/result";
|
||||
import type { Message, MessageEntity } from "~/composables/useChat";
|
||||
import type { Agent } from "~/composables/useAgents";
|
||||
import { resolveFileUrl } from "~~/utils/url";
|
||||
|
||||
export const buildMessageTree = (flatMessages: MessageEntity[]) => {
|
||||
const messagesMap = new Map(flatMessages.map(m => [m.id, { ...m, children: [] as MessageEntity[] }]));
|
||||
@@ -50,16 +51,18 @@ export const marshallMessages = (agent: Agent, messages: Readonly<MessageEntity[
|
||||
switch (message.role) {
|
||||
case 'user': {
|
||||
const attachments = message.attachments.map(attachment => {
|
||||
const url = resolveFileUrl(attachment.file.url);
|
||||
|
||||
if (attachment.file.mimeType.startsWith('image/')) {
|
||||
return {
|
||||
type: 'image',
|
||||
image: attachment.file.url,
|
||||
image: url,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
type: 'file',
|
||||
data: attachment.file.url,
|
||||
data: url,
|
||||
filename: attachment.file.name,
|
||||
mediaType: attachment.file.mimeType,
|
||||
};
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
export const resolveFileUrl = (path: string): string => {
|
||||
if (path.startsWith('http://') || path.startsWith('https://') || path.startsWith('blob:') || path.startsWith('data:')) {
|
||||
return path;
|
||||
}
|
||||
const config = useRuntimeConfig();
|
||||
return `${config.public.publicUrl}${path}`;
|
||||
};
|
||||
Reference in New Issue
Block a user