refactor: Cleanup
This commit is contained in:
parent
5871923ffe
commit
6c61742d54
|
|
@ -1,6 +1,7 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { Copy, Eye } from '@lucide/svelte';
|
import { Copy, Eye } from '@lucide/svelte';
|
||||||
import { copyCodeToClipboard } from '$lib/utils';
|
import { copyCodeToClipboard } from '$lib/utils';
|
||||||
|
import { FileTypeText } from '$lib/enums';
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
code: string;
|
code: string;
|
||||||
|
|
@ -11,7 +12,7 @@
|
||||||
|
|
||||||
let { code, language, disabled = false, onPreview }: Props = $props();
|
let { code, language, disabled = false, onPreview }: Props = $props();
|
||||||
|
|
||||||
const showPreview = $derived(language?.toLowerCase() === 'html');
|
const showPreview = $derived(language?.toLowerCase() === FileTypeText.HTML);
|
||||||
|
|
||||||
function handleCopy() {
|
function handleCopy() {
|
||||||
if (disabled) return;
|
if (disabled) return;
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,12 @@
|
||||||
import { mcpStore } from '$lib/stores/mcp.svelte';
|
import { mcpStore } from '$lib/stores/mcp.svelte';
|
||||||
import { getFaviconUrl } from '$lib/utils';
|
import { getFaviconUrl } from '$lib/utils';
|
||||||
import type { MCPResourceAttachment, MCPResourceInfo } from '$lib/types';
|
import type { MCPResourceAttachment, MCPResourceInfo } from '$lib/types';
|
||||||
|
import {
|
||||||
|
IMAGE_FILE_EXTENSION_REGEX,
|
||||||
|
CODE_FILE_EXTENSION_REGEX,
|
||||||
|
TEXT_FILE_EXTENSION_REGEX
|
||||||
|
} from '$lib/constants/mcp-resource';
|
||||||
|
import { MimeTypePrefix, MimeTypeIncludes, UriPattern } from '$lib/enums';
|
||||||
import * as Tooltip from '$lib/components/ui/tooltip';
|
import * as Tooltip from '$lib/components/ui/tooltip';
|
||||||
import { RemoveButton } from '../../actions';
|
import { RemoveButton } from '../../actions';
|
||||||
|
|
||||||
|
|
@ -20,21 +26,21 @@
|
||||||
const mimeType = resource.mimeType?.toLowerCase() || '';
|
const mimeType = resource.mimeType?.toLowerCase() || '';
|
||||||
const uri = resource.uri.toLowerCase();
|
const uri = resource.uri.toLowerCase();
|
||||||
|
|
||||||
if (mimeType.startsWith('image/') || /\.(png|jpg|jpeg|gif|svg|webp)$/.test(uri)) {
|
if (mimeType.startsWith(MimeTypePrefix.IMAGE) || IMAGE_FILE_EXTENSION_REGEX.test(uri)) {
|
||||||
return Image;
|
return Image;
|
||||||
}
|
}
|
||||||
if (
|
if (
|
||||||
mimeType.includes('json') ||
|
mimeType.includes(MimeTypeIncludes.JSON) ||
|
||||||
mimeType.includes('javascript') ||
|
mimeType.includes(MimeTypeIncludes.JAVASCRIPT) ||
|
||||||
mimeType.includes('typescript') ||
|
mimeType.includes(MimeTypeIncludes.TYPESCRIPT) ||
|
||||||
/\.(js|ts|json|yaml|yml|xml|html|css)$/.test(uri)
|
CODE_FILE_EXTENSION_REGEX.test(uri)
|
||||||
) {
|
) {
|
||||||
return Code;
|
return Code;
|
||||||
}
|
}
|
||||||
if (mimeType.includes('text') || /\.(txt|md|log)$/.test(uri)) {
|
if (mimeType.includes(MimeTypePrefix.TEXT) || TEXT_FILE_EXTENSION_REGEX.test(uri)) {
|
||||||
return FileText;
|
return FileText;
|
||||||
}
|
}
|
||||||
if (uri.includes('database') || uri.includes('db://')) {
|
if (uri.includes(UriPattern.DATABASE_KEYWORD) || uri.includes(UriPattern.DATABASE_SCHEME)) {
|
||||||
return Database;
|
return Database;
|
||||||
}
|
}
|
||||||
return File;
|
return File;
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,11 @@
|
||||||
} from '$lib/components/app';
|
} from '$lib/components/app';
|
||||||
import { INPUT_CLASSES } from '$lib/constants/css-classes';
|
import { INPUT_CLASSES } from '$lib/constants/css-classes';
|
||||||
import { SETTING_CONFIG_DEFAULT } from '$lib/constants/settings-config';
|
import { SETTING_CONFIG_DEFAULT } from '$lib/constants/settings-config';
|
||||||
import { INITIAL_FILE_SIZE, PROMPT_CONTENT_SEPARATOR } from '$lib/constants/chat-form';
|
import {
|
||||||
|
CLIPBOARD_CONTENT_QUOTE_PREFIX,
|
||||||
|
INITIAL_FILE_SIZE,
|
||||||
|
PROMPT_CONTENT_SEPARATOR
|
||||||
|
} from '$lib/constants/chat-form';
|
||||||
import { ContentPartType, KeyboardKey, MimeTypeText, SpecialFileType } from '$lib/enums';
|
import { ContentPartType, KeyboardKey, MimeTypeText, SpecialFileType } from '$lib/enums';
|
||||||
import { config } from '$lib/stores/settings.svelte';
|
import { config } from '$lib/stores/settings.svelte';
|
||||||
import { modelOptions, selectedModelId } from '$lib/stores/models.svelte';
|
import { modelOptions, selectedModelId } from '$lib/stores/models.svelte';
|
||||||
|
|
@ -264,7 +268,7 @@
|
||||||
|
|
||||||
const text = event.clipboardData.getData(MimeTypeText.PLAIN);
|
const text = event.clipboardData.getData(MimeTypeText.PLAIN);
|
||||||
|
|
||||||
if (text.startsWith('"')) {
|
if (text.startsWith(CLIPBOARD_CONTENT_QUOTE_PREFIX)) {
|
||||||
const parsed = parseClipboardContent(text);
|
const parsed = parseClipboardContent(text);
|
||||||
|
|
||||||
if (parsed.textAttachments.length > 0 || parsed.mcpPromptAttachments.length > 0) {
|
if (parsed.textAttachments.length > 0 || parsed.mcpPromptAttachments.length > 0) {
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@
|
||||||
import { mcpStore } from '$lib/stores/mcp.svelte';
|
import { mcpStore } from '$lib/stores/mcp.svelte';
|
||||||
import { SvelteMap } from 'svelte/reactivity';
|
import { SvelteMap } from 'svelte/reactivity';
|
||||||
import { McpPromptVariant } from '$lib/enums';
|
import { McpPromptVariant } from '$lib/enums';
|
||||||
import TruncatedText from '../../misc/TruncatedText.svelte';
|
import { TruncatedText } from '$lib/components/app/misc';
|
||||||
import * as Tooltip from '$lib/components/ui/tooltip';
|
import * as Tooltip from '$lib/components/ui/tooltip';
|
||||||
|
|
||||||
interface ContentPart {
|
interface ContentPart {
|
||||||
|
|
|
||||||
|
|
@ -1,2 +1,3 @@
|
||||||
export const INITIAL_FILE_SIZE = 0;
|
export const INITIAL_FILE_SIZE = 0;
|
||||||
export const PROMPT_CONTENT_SEPARATOR = '\n\n';
|
export const PROMPT_CONTENT_SEPARATOR = '\n\n';
|
||||||
|
export const CLIPBOARD_CONTENT_QUOTE_PREFIX = '"';
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,4 @@
|
||||||
|
// File extension patterns for resource type detection
|
||||||
|
export const IMAGE_FILE_EXTENSION_REGEX = /\.(png|jpg|jpeg|gif|svg|webp)$/;
|
||||||
|
export const CODE_FILE_EXTENSION_REGEX = /\.(js|ts|json|yaml|yml|xml|html|css)$/;
|
||||||
|
export const TEXT_FILE_EXTENSION_REGEX = /\.(txt|md|log)$/;
|
||||||
|
|
@ -143,6 +143,24 @@ export enum FileExtensionText {
|
||||||
CS = '.cs'
|
CS = '.cs'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MIME type prefixes and includes for content detection
|
||||||
|
export enum MimeTypePrefix {
|
||||||
|
IMAGE = 'image/',
|
||||||
|
TEXT = 'text'
|
||||||
|
}
|
||||||
|
|
||||||
|
export enum MimeTypeIncludes {
|
||||||
|
JSON = 'json',
|
||||||
|
JAVASCRIPT = 'javascript',
|
||||||
|
TYPESCRIPT = 'typescript'
|
||||||
|
}
|
||||||
|
|
||||||
|
// URI patterns for content detection
|
||||||
|
export enum UriPattern {
|
||||||
|
DATABASE_KEYWORD = 'database',
|
||||||
|
DATABASE_SCHEME = 'db://'
|
||||||
|
}
|
||||||
|
|
||||||
// MIME type enums
|
// MIME type enums
|
||||||
export enum MimeTypeApplication {
|
export enum MimeTypeApplication {
|
||||||
PDF = 'application/pdf'
|
PDF = 'application/pdf'
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,9 @@ export {
|
||||||
FileExtensionAudio,
|
FileExtensionAudio,
|
||||||
FileExtensionPdf,
|
FileExtensionPdf,
|
||||||
FileExtensionText,
|
FileExtensionText,
|
||||||
|
MimeTypePrefix,
|
||||||
|
MimeTypeIncludes,
|
||||||
|
UriPattern,
|
||||||
MimeTypeApplication,
|
MimeTypeApplication,
|
||||||
MimeTypeAudio,
|
MimeTypeAudio,
|
||||||
MimeTypeImage,
|
MimeTypeImage,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue