mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-05 16:23:36 +00:00
Don't upload images to Blossom
This commit is contained in:
5 files changed
+39
-93
No files matched your search
Generated
+11
-31
@@ -195,7 +195,6 @@
|
||||
"integrity": "sha512-e7jT4DxYvIDLk1ZHmU/m/mB19rex9sv0c2ftBtjSBv+kVM/902eh0fINUzD7UwLLNR+jU585GxUJ8/EBfAM5fw==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"@babel/code-frame": "^7.27.1",
|
||||
"@babel/generator": "^7.28.5",
|
||||
@@ -1831,7 +1830,6 @@
|
||||
}
|
||||
],
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"engines": {
|
||||
"node": ">=18"
|
||||
},
|
||||
@@ -1855,7 +1853,6 @@
|
||||
}
|
||||
],
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"engines": {
|
||||
"node": ">=18"
|
||||
}
|
||||
@@ -1877,7 +1874,6 @@
|
||||
"resolved": "https://registry.npmjs.org/@dnd-kit/core/-/core-6.3.1.tgz",
|
||||
"integrity": "sha512-xkGBRQQab4RLwgXxoqETICr6S5JlogafbhNsidmrkVv2YRs5MLwpjoF2qpiGjQt8S9AoxtIV603s0GIUpY5eYQ==",
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"@dnd-kit/accessibility": "^3.1.1",
|
||||
"@dnd-kit/utilities": "^3.2.2",
|
||||
@@ -5408,7 +5404,8 @@
|
||||
"resolved": "https://registry.npmjs.org/@types/aria-query/-/aria-query-5.0.4.tgz",
|
||||
"integrity": "sha512-rfT93uj5s0PRL7EzccGMs3brplhcrghnDoV26NqKhCAS1hVo+WdNsPvE/yb6ilfr5hi2MEk6d5EWJTKdxg8jVw==",
|
||||
"dev": true,
|
||||
"license": "MIT"
|
||||
"license": "MIT",
|
||||
"peer": true
|
||||
},
|
||||
"node_modules/@types/cacheable-request": {
|
||||
"version": "6.0.3",
|
||||
@@ -5650,7 +5647,6 @@
|
||||
"resolved": "https://registry.npmjs.org/@types/react/-/react-18.3.20.tgz",
|
||||
"integrity": "sha512-IPaCZN7PShZK/3t6Q87pfTkRm6oLTd4vztyoj+cbHUF1g3FfVb2tFIL79uCRKEfv16AhqDMBywP2VW3KIZUvcg==",
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"@types/prop-types": "*",
|
||||
"csstype": "^3.0.2"
|
||||
@@ -5662,7 +5658,6 @@
|
||||
"integrity": "sha512-MEe3UeoENYVFXzoXEWsvcpg6ZvlrFNlOQ7EOsvhI3CfAXwzPfO8Qwuxd40nepsYKqyyVQnTdEfv68q91yLcKrQ==",
|
||||
"devOptional": true,
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"peerDependencies": {
|
||||
"@types/react": "^18.0.0"
|
||||
}
|
||||
@@ -5767,7 +5762,6 @@
|
||||
"integrity": "sha512-oU/OtYVydhXnumd0BobL9rkJg7wFJ9bFFPmSmB/bf/XWN85hlViji59ko6bSKBXyseT9V8l+CN1nwmlbiN0G7Q==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"@typescript-eslint/scope-manager": "8.31.1",
|
||||
"@typescript-eslint/types": "8.31.1",
|
||||
@@ -6114,7 +6108,6 @@
|
||||
"resolved": "https://registry.npmjs.org/acorn/-/acorn-8.15.0.tgz",
|
||||
"integrity": "sha512-NZyJarBfL7nWwIq+FDL6Zp/yHEhePMNnnJ0y3qfieCrmNvYct8uvtiV41UvlSe6apAfk0fY1FbWx+NwfmpvtTg==",
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"bin": {
|
||||
"acorn": "bin/acorn"
|
||||
},
|
||||
@@ -6559,7 +6552,6 @@
|
||||
}
|
||||
],
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"baseline-browser-mapping": "^2.8.19",
|
||||
"caniuse-lite": "^1.0.30001751",
|
||||
@@ -6819,7 +6811,6 @@
|
||||
"resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.6.0.tgz",
|
||||
"integrity": "sha512-7VT13fmjotKpGipCW9JEQAusEPE+Ei8nl6/g4FBAmIm0GOOLMua9NDDo/DWp0ZAxCr3cPq5ZpBqmPAQgDda2Pw==",
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"anymatch": "~3.1.2",
|
||||
"braces": "~3.0.2",
|
||||
@@ -7558,7 +7549,8 @@
|
||||
"resolved": "https://registry.npmjs.org/dom-accessibility-api/-/dom-accessibility-api-0.5.16.tgz",
|
||||
"integrity": "sha512-X7BJ2yElsnOJ30pZF4uIIDfBEVgF4XEBxL9Bxhy6dnrm5hkzqmsWHGTiHqRiITNhMyFLyAiWndIJP7Z1NTteDg==",
|
||||
"dev": true,
|
||||
"license": "MIT"
|
||||
"license": "MIT",
|
||||
"peer": true
|
||||
},
|
||||
"node_modules/dom-helpers": {
|
||||
"version": "5.2.1",
|
||||
@@ -7636,8 +7628,7 @@
|
||||
"version": "8.6.0",
|
||||
"resolved": "https://registry.npmjs.org/embla-carousel/-/embla-carousel-8.6.0.tgz",
|
||||
"integrity": "sha512-SjWyZBHJPbqxHOzckOfo8lHisEaJWmwd23XppYFYVh10bU66/Pn5tkVkbkCMZVdbUE5eTCI2nD8OyIP4Z+uwkA==",
|
||||
"license": "MIT",
|
||||
"peer": true
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/embla-carousel-react": {
|
||||
"version": "8.6.0",
|
||||
@@ -7936,7 +7927,6 @@
|
||||
"integrity": "sha512-QldCVh/ztyKJJZLr4jXNUByx3gR+TDYZCRXEktiZoUR3PGy4qCmSbkxcIle8GEwGpb5JBZazlaJ/CxLidXdEbQ==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"@eslint-community/eslint-utils": "^4.2.0",
|
||||
"@eslint-community/regexpp": "^4.12.1",
|
||||
@@ -9284,7 +9274,6 @@
|
||||
}
|
||||
],
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.27.6"
|
||||
},
|
||||
@@ -10054,7 +10043,6 @@
|
||||
"integrity": "sha512-Cvc9WUhxSMEo4McES3P7oK3QaXldCfNWp7pl2NNeiIFlCoLr3kfq9kb1fxftiwk1FLV7CvpvDfonxtzUDeSOPg==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"cssstyle": "^4.2.1",
|
||||
"data-urls": "^5.0.0",
|
||||
@@ -10451,6 +10439,7 @@
|
||||
"integrity": "sha512-h5bgJWpxJNswbU7qCrV0tIKQCaS3blPDrqKWx+QxzuzL1zGUzij9XCWLrSLsJPu5t+eWA/ycetzYAO5IOMcWAQ==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"bin": {
|
||||
"lz-string": "bin/bin.js"
|
||||
}
|
||||
@@ -12154,7 +12143,6 @@
|
||||
}
|
||||
],
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"nanoid": "^3.3.8",
|
||||
"picocolors": "^1.1.1",
|
||||
@@ -12322,6 +12310,7 @@
|
||||
"integrity": "sha512-Qb1gy5OrP5+zDf2Bvnzdl3jsTf1qXVMazbvCoKhtKqVs4/YK4ozX4gKQJJVyNe+cajNPn0KoC0MC3FUmaHWEmQ==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"ansi-regex": "^5.0.1",
|
||||
"ansi-styles": "^5.0.0",
|
||||
@@ -12337,6 +12326,7 @@
|
||||
"integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"engines": {
|
||||
"node": ">=8"
|
||||
}
|
||||
@@ -12347,6 +12337,7 @@
|
||||
"integrity": "sha512-Cxwpt2SfTzTtXcfOlzGEee8O+c+MmUgGrNiBcXnuWxuFJHe6a5Hz7qwhwe5OgaSYI0IJvkLqWX1ASG+cJOkEiA==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"engines": {
|
||||
"node": ">=10"
|
||||
},
|
||||
@@ -12359,7 +12350,8 @@
|
||||
"resolved": "https://registry.npmjs.org/react-is/-/react-is-17.0.2.tgz",
|
||||
"integrity": "sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w==",
|
||||
"dev": true,
|
||||
"license": "MIT"
|
||||
"license": "MIT",
|
||||
"peer": true
|
||||
},
|
||||
"node_modules/prismjs": {
|
||||
"version": "1.30.0",
|
||||
@@ -12499,7 +12491,6 @@
|
||||
"resolved": "https://registry.npmjs.org/react/-/react-18.3.1.tgz",
|
||||
"integrity": "sha512-wS+hAgJShR0KhEvPJArfuPVN1+Hz1t0Y6n5jLrGQbkb4urgPE/0Rve+1kMB1v/oWgHgm4WIcV+i7F2pTVj+2iQ==",
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"loose-envify": "^1.1.0"
|
||||
},
|
||||
@@ -12526,7 +12517,6 @@
|
||||
"resolved": "https://registry.npmjs.org/react-dom/-/react-dom-18.3.1.tgz",
|
||||
"integrity": "sha512-5m4nQKp+rZRb09LNH59GM4BxTh9251/ylbKIbpe7TpGxfJ+9kv6BLkLBXIjjspbgbnIBNqlI23tRnTWT0snUIw==",
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"loose-envify": "^1.1.0",
|
||||
"scheduler": "^0.23.2"
|
||||
@@ -12552,7 +12542,6 @@
|
||||
"resolved": "https://registry.npmjs.org/react-hook-form/-/react-hook-form-7.56.1.tgz",
|
||||
"integrity": "sha512-qWAVokhSpshhcEuQDSANHx3jiAEFzu2HAaaQIzi/r9FNPm1ioAvuJSD4EuZzWd7Al7nTRKcKPnBKO7sRn+zavQ==",
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"engines": {
|
||||
"node": ">=18.0.0"
|
||||
},
|
||||
@@ -12601,7 +12590,6 @@
|
||||
"resolved": "https://registry.npmjs.org/react-markdown/-/react-markdown-10.1.0.tgz",
|
||||
"integrity": "sha512-qKxVopLT/TyA6BX3Ue5NwabOsAzm0Q7kAPwq6L+wWDwisYs7R8vZ0nRXqq6rkueboxpkjvLGU9fWifiX/ZZFxQ==",
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"@types/hast": "^3.0.0",
|
||||
"@types/mdast": "^4.0.0",
|
||||
@@ -13184,7 +13172,6 @@
|
||||
"integrity": "sha512-C5VvvgCCyfyotVITIAv+4efVytl5F7wt+/I2i9q9GZcEXW9BP52YYOXC58igUi+LFZVHukErIIqQSWwv/M3WRw==",
|
||||
"devOptional": true,
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"@types/estree": "1.0.7"
|
||||
},
|
||||
@@ -14236,7 +14223,6 @@
|
||||
"resolved": "https://registry.npmjs.org/tailwindcss/-/tailwindcss-3.4.17.tgz",
|
||||
"integrity": "sha512-w33E2aCvSDP0tW9RZuNXadXlkHXqFzSkQew/aIa2i/Sj8fThxwovwlXHSPXTbAHwEIhBFXAedUhP2tueAKP8Og==",
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"@alloc/quick-lru": "^5.2.0",
|
||||
"arg": "^5.0.2",
|
||||
@@ -14440,7 +14426,6 @@
|
||||
"integrity": "sha512-M7BAV6Rlcy5u+m6oPhAPFgJTzAioX/6B0DxyvDlo9l8+T3nLKbrczg2WLUyzd45L8RqfUMyGPzekbMvX2Ldkwg==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
},
|
||||
@@ -14713,7 +14698,6 @@
|
||||
"integrity": "sha512-p1diW6TqL9L07nNxvRMM7hMMw4c5XOo/1ibL4aAIGmSAt9slTE1Xgw5KWuof2uTOvCg9BY7ZRi+GaF+7sfgPeQ==",
|
||||
"devOptional": true,
|
||||
"license": "Apache-2.0",
|
||||
"peer": true,
|
||||
"bin": {
|
||||
"tsc": "bin/tsc",
|
||||
"tsserver": "bin/tsserver"
|
||||
@@ -15223,7 +15207,6 @@
|
||||
"integrity": "sha512-cZn6NDFE7wdTpINgs++ZJ4N49W2vRp8LCKrn3Ob1kYNtOo21vfDoaV5GzBfLU4MovSAB8uNRm4jgzVQZ+mBzPQ==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"esbuild": "^0.25.0",
|
||||
"fdir": "^6.4.4",
|
||||
@@ -15368,7 +15351,6 @@
|
||||
"integrity": "sha512-M7BAV6Rlcy5u+m6oPhAPFgJTzAioX/6B0DxyvDlo9l8+T3nLKbrczg2WLUyzd45L8RqfUMyGPzekbMvX2Ldkwg==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
},
|
||||
@@ -15839,7 +15821,6 @@
|
||||
"integrity": "sha512-B/gBuNg5SiMTrPkC+A2+cW0RszwxYmn6VYxB/inlBStS5nx6xHIt/ehKRhIMhqusl7a8LjQoZnjCs5vhwxOQ1g==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"dependencies": {
|
||||
"fast-deep-equal": "^3.1.3",
|
||||
"fast-uri": "^3.0.1",
|
||||
@@ -15916,7 +15897,6 @@
|
||||
"integrity": "sha512-fS6iqSPZDs3dr/y7Od6y5nha8dW1YnbgtsyotCVvoFGKbERG++CVRFv1meyGDE1SNItQA8BrnCw7ScdAhRJ3XQ==",
|
||||
"dev": true,
|
||||
"license": "MIT",
|
||||
"peer": true,
|
||||
"bin": {
|
||||
"rollup": "dist/bin/rollup"
|
||||
},
|
||||
|
||||
@@ -44,7 +44,6 @@ import { Quilly } from '@/components/Quilly';
|
||||
import { ShakespeareLogo } from '@/components/ShakespeareLogo';
|
||||
import { ChatInput } from '@/components/Shakespeare/ChatInput';
|
||||
import { buildMessageContent } from '@/lib/buildMessageContent';
|
||||
import { useUploadFile } from '@/hooks/useUploadFile';
|
||||
|
||||
// Clean interfaces now handled by proper hooks
|
||||
|
||||
@@ -78,7 +77,6 @@ export const ChatPane = forwardRef<ChatPaneRef, ChatPaneProps>(({
|
||||
const { fs } = useFS();
|
||||
const { git } = useGit();
|
||||
const { user } = useCurrentUser();
|
||||
const { mutateAsync: uploadFile } = useUploadFile();
|
||||
const { models } = useProviderModels();
|
||||
const { config } = useAppContext();
|
||||
const { projectsPath, tmpPath, pluginsPath } = useFSPaths();
|
||||
@@ -441,20 +439,19 @@ export const ChatPane = forwardRef<ChatPaneRef, ChatPaneProps>(({
|
||||
const modelToUse = providerModel.trim();
|
||||
|
||||
// Build message content from input and attached files
|
||||
// Pass uploadFile function if user is logged in
|
||||
// Images are converted to base64-encoded data URLs
|
||||
const messageContent = await buildMessageContent(
|
||||
input,
|
||||
attachedFiles,
|
||||
fs,
|
||||
tmpPath,
|
||||
user ? uploadFile : undefined
|
||||
tmpPath
|
||||
);
|
||||
|
||||
// Add model to recently used when sending a message
|
||||
addRecentlyUsedModel(modelToUse);
|
||||
|
||||
await sendMessage(messageContent, modelToUse);
|
||||
}, [addRecentlyUsedModel, fs, isConfigured, isLoading, providerModel, sendMessage, tmpPath, uploadFile, user]);
|
||||
}, [addRecentlyUsedModel, fs, isConfigured, isLoading, providerModel, sendMessage, tmpPath]);
|
||||
|
||||
// Handle textarea focus - show onboarding if not configured
|
||||
const handleTextareaFocus = useCallback(() => {
|
||||
|
||||
@@ -9,42 +9,41 @@ type ContentPart = OpenAI.Chat.Completions.ChatCompletionContentPartText | OpenA
|
||||
/**
|
||||
* Builds message content from text input, image URLs, and attached files.
|
||||
* Downloads image URLs to VFS and processes uploaded files.
|
||||
*
|
||||
*
|
||||
* - All image formats are included in the message content for UI display
|
||||
* - SessionManager filters to only pass JPG/JPEG/PNG to the OpenAI API
|
||||
* - All files are saved to VFS and get a text part with the path
|
||||
*
|
||||
* - Images are converted to base64-encoded data URLs for API consumption
|
||||
*
|
||||
* Returns content as either a string (for simple text) or an array of content parts.
|
||||
*
|
||||
*
|
||||
* @param input - User text input that may contain image URLs
|
||||
* @param attachedFiles - Array of files to attach
|
||||
* @param fs - Filesystem instance for saving files
|
||||
* @param tmpPath - Temporary directory path for file storage
|
||||
* @param uploadFile - Optional upload function from useUploadFile hook for converting files to URLs
|
||||
* @returns Promise resolving to message content (string or array of content parts)
|
||||
*/
|
||||
export async function buildMessageContent(
|
||||
input: string,
|
||||
attachedFiles: File[],
|
||||
fs: JSRuntimeFS,
|
||||
tmpPath = '/tmp',
|
||||
uploadFile?: (file: File) => Promise<Array<[string, string] | string[]>>
|
||||
tmpPath = '/tmp'
|
||||
): Promise<string | ContentPart[]> {
|
||||
const contentParts: ContentPart[] = [];
|
||||
|
||||
// Parse user input to detect image URLs and split into content parts
|
||||
if (input.trim()) {
|
||||
const parsedParts = parseImageUrls(input.trim());
|
||||
|
||||
|
||||
// Process each part: download image URLs to VFS and add text parts with VFS paths
|
||||
for (const part of parsedParts) {
|
||||
if (part.type === 'image_url') {
|
||||
// Download image to VFS and get the path
|
||||
const result = await urlToFile(part.image_url.url, fs, tmpPath);
|
||||
|
||||
|
||||
// Always add image_url part for UI display (all formats)
|
||||
contentParts.push(part);
|
||||
|
||||
|
||||
// Always add text part with VFS path so AI knows where the file is (can manipulate it)
|
||||
if (result?.vfsPath) {
|
||||
contentParts.push({
|
||||
@@ -64,18 +63,18 @@ export async function buildMessageContent(
|
||||
try {
|
||||
// Save file to VFS (always do this)
|
||||
const savedPath = await saveFileToTmp(fs, file, tmpPath);
|
||||
|
||||
|
||||
// Always add text part with VFS path
|
||||
const textPart: ContentPart = {
|
||||
type: 'text',
|
||||
text: `Added file: ${savedPath}`
|
||||
};
|
||||
|
||||
// For all image types, also add as image_url for UI display (if uploadFile available)
|
||||
|
||||
// For all image types, also add as image_url for UI display with base64 encoding
|
||||
const isImage = file.type.startsWith('image/');
|
||||
if (isImage && uploadFile) {
|
||||
if (isImage) {
|
||||
try {
|
||||
const imageUrl = await fileToUrl(file, uploadFile);
|
||||
const imageUrl = await fileToUrl(file);
|
||||
// Return both parts: image_url for UI display and text for VFS path
|
||||
return [textPart, {
|
||||
type: 'image_url' as const,
|
||||
@@ -83,10 +82,10 @@ export async function buildMessageContent(
|
||||
}];
|
||||
} catch (error) {
|
||||
// If URL conversion fails, just use text part
|
||||
console.warn('Failed to convert image to URL, using text part only:', error);
|
||||
console.warn('Failed to convert image to base64, using text part only:', error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return [textPart];
|
||||
} catch (error) {
|
||||
console.error('Failed to save file:', error);
|
||||
@@ -98,7 +97,7 @@ export async function buildMessageContent(
|
||||
});
|
||||
|
||||
const fileResults = await Promise.all(filePromises);
|
||||
|
||||
|
||||
// Flatten the results (each file can return multiple parts)
|
||||
for (const parts of fileResults) {
|
||||
contentParts.push(...parts);
|
||||
@@ -109,7 +108,7 @@ export async function buildMessageContent(
|
||||
if (contentParts.length === 1 && contentParts[0].type === 'text') {
|
||||
return contentParts[0].text;
|
||||
}
|
||||
|
||||
|
||||
// Return array for multiple parts or if contains image URLs
|
||||
return contentParts;
|
||||
}
|
||||
|
||||
+6
-31
@@ -2,37 +2,12 @@ import type { JSRuntimeFS } from '@/lib/JSRuntime';
|
||||
import { generateUniqueFilename } from './fileUtils';
|
||||
|
||||
/**
|
||||
* Converts a File to a URL string for API consumption.
|
||||
* Tries useUploadFile first if available, otherwise falls back to data URL.
|
||||
*
|
||||
* Converts a File to a base64-encoded data URL for API consumption.
|
||||
*
|
||||
* @param file - The file to convert
|
||||
* @param uploadFile - Optional upload function from useUploadFile hook
|
||||
* @returns Promise resolving to URL string
|
||||
* @returns Promise resolving to base64 data URL string
|
||||
*/
|
||||
export async function fileToUrl(
|
||||
file: File,
|
||||
uploadFile?: (file: File) => Promise<Array<[string, string] | string[]>>
|
||||
): Promise<string> {
|
||||
// Try useUploadFile first if available
|
||||
if (uploadFile) {
|
||||
try {
|
||||
const tags = await uploadFile(file);
|
||||
// Extract URL from NIP-94 compatible tags
|
||||
// The first tag contains the URL
|
||||
if (tags && tags.length > 0 && tags[0]) {
|
||||
const firstTag = tags[0];
|
||||
// Handle both tuple [string, string] and array string[] formats
|
||||
if (Array.isArray(firstTag) && firstTag.length > 1) {
|
||||
return firstTag[1] as string;
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn('Failed to upload file via useUploadFile, falling back to data URL:', error);
|
||||
// Fall through to data URL fallback
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback to data URL
|
||||
export async function fileToUrl(file: File): Promise<string> {
|
||||
return new Promise((resolve, reject) => {
|
||||
const reader = new FileReader();
|
||||
reader.onload = () => {
|
||||
@@ -53,7 +28,7 @@ export async function fileToUrl(
|
||||
* Converts a URL to a file saved in the VFS.
|
||||
* Downloads an image from a URL and saves it to the VFS.
|
||||
* Returns both the original URL (for API calls) and the VFS path (for reference).
|
||||
*
|
||||
*
|
||||
* @param imageUrl - The image URL to download
|
||||
* @param fs - Filesystem instance for saving files
|
||||
* @param tmpPath - Temporary directory path for file storage
|
||||
@@ -113,7 +88,7 @@ export async function urlToFile(
|
||||
let filename = 'downloaded_image';
|
||||
const urlPath = new URL(imageUrl).pathname;
|
||||
const urlFilename = urlPath.split('/').pop();
|
||||
|
||||
|
||||
if (urlFilename && /\.(jpg|jpeg|png|gif|webp|svg|bmp|ico)$/i.test(urlFilename)) {
|
||||
filename = urlFilename;
|
||||
} else {
|
||||
|
||||
+2
-7
@@ -24,8 +24,6 @@ import { ArrowUp } from 'lucide-react';
|
||||
import { useSeoMeta } from '@unhead/react';
|
||||
import { ShakespeareLogo } from '@/components/ShakespeareLogo';
|
||||
import { AppShowcase } from '@/components/AppShowcase';
|
||||
import { useUploadFile } from '@/hooks/useUploadFile';
|
||||
import { useCurrentUser } from '@/hooks/useCurrentUser';
|
||||
|
||||
export default function Index() {
|
||||
const { t } = useTranslation();
|
||||
@@ -50,8 +48,6 @@ export default function Index() {
|
||||
});
|
||||
const isMobile = useIsMobile();
|
||||
const [attachedFiles, setAttachedFiles] = useState<File[]>([]);
|
||||
const { user } = useCurrentUser();
|
||||
const { mutateAsync: uploadFile } = useUploadFile();
|
||||
const [isDragOver, setIsDragOver] = useState(false);
|
||||
const [quillyError, setQuillyError] = useState<Error | null>(null);
|
||||
|
||||
@@ -235,13 +231,12 @@ export default function Index() {
|
||||
const project = await projectsManager.createProject(prompt.trim(), config.projectTemplate, projectId);
|
||||
|
||||
// Build message content from input and attached files
|
||||
// Pass uploadFile function if user is logged in
|
||||
// Images are converted to base64-encoded data URLs
|
||||
const messageContent = await buildMessageContent(
|
||||
prompt.trim(),
|
||||
attachedFiles,
|
||||
fs,
|
||||
undefined,
|
||||
user ? uploadFile : undefined
|
||||
undefined
|
||||
);
|
||||
|
||||
// Store the initial message in chat history using DotAI
|
||||
|
||||
Reference in new issue
Block a user