refactor(agent-attachments): use agent image mime types directly
This commit is contained in:
parent
a7ed38e167
commit
1cae11da34
3 changed files with 8 additions and 10 deletions
|
|
@ -1,7 +1,7 @@
|
||||||
import type {
|
import type {
|
||||||
AgentAttachmentCapability,
|
AgentAttachmentCapability,
|
||||||
AgentAttachmentCapabilityTarget,
|
AgentAttachmentCapabilityTarget,
|
||||||
ProviderImageMimeType,
|
AgentImageMimeType,
|
||||||
} from './types';
|
} from './types';
|
||||||
|
|
||||||
const DEFAULT_IMAGE_BYTES_PER_PROVIDER = 4 * 1024 * 1024;
|
const DEFAULT_IMAGE_BYTES_PER_PROVIDER = 4 * 1024 * 1024;
|
||||||
|
|
@ -18,7 +18,7 @@ export const CLAUDE_IMAGE_MIME_TYPES = [
|
||||||
|
|
||||||
function supportedImagesOnly(
|
function supportedImagesOnly(
|
||||||
displayText: string,
|
displayText: string,
|
||||||
supportedImageMimeTypes: readonly ProviderImageMimeType[] = NATIVE_IMAGE_MIME_TYPES
|
supportedImageMimeTypes: readonly AgentImageMimeType[] = NATIVE_IMAGE_MIME_TYPES
|
||||||
): AgentAttachmentCapability {
|
): AgentAttachmentCapability {
|
||||||
return {
|
return {
|
||||||
supportsImages: true,
|
supportsImages: true,
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@ export const AGENT_ATTACHMENT_SCHEMA_VERSION = 1 as const;
|
||||||
export type AgentAttachmentKind = 'image' | 'file' | 'unsupported';
|
export type AgentAttachmentKind = 'image' | 'file' | 'unsupported';
|
||||||
|
|
||||||
export type AgentImageMimeType = 'image/png' | 'image/jpeg' | 'image/gif' | 'image/webp';
|
export type AgentImageMimeType = 'image/png' | 'image/jpeg' | 'image/gif' | 'image/webp';
|
||||||
export type ProviderImageMimeType = AgentImageMimeType;
|
|
||||||
export type ProviderFileMimeType = 'application/pdf' | 'text/*';
|
export type ProviderFileMimeType = 'application/pdf' | 'text/*';
|
||||||
|
|
||||||
export type AttachmentDeliveryFailureCode =
|
export type AttachmentDeliveryFailureCode =
|
||||||
|
|
@ -98,7 +97,7 @@ export interface AgentAttachmentCapabilityTarget {
|
||||||
export interface AgentAttachmentCapability {
|
export interface AgentAttachmentCapability {
|
||||||
supportsImages: boolean;
|
supportsImages: boolean;
|
||||||
supportsFiles: boolean;
|
supportsFiles: boolean;
|
||||||
supportedImageMimeTypes: ProviderImageMimeType[];
|
supportedImageMimeTypes: AgentImageMimeType[];
|
||||||
supportedFileMimeTypes: ProviderFileMimeType[];
|
supportedFileMimeTypes: ProviderFileMimeType[];
|
||||||
maxImages: number;
|
maxImages: number;
|
||||||
maxFiles: number;
|
maxFiles: number;
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,6 @@ import type {
|
||||||
AgentImageMimeType,
|
AgentImageMimeType,
|
||||||
AttachmentValidationResult,
|
AttachmentValidationResult,
|
||||||
ImageOptimizationBudget,
|
ImageOptimizationBudget,
|
||||||
ProviderImageMimeType,
|
|
||||||
} from './types';
|
} from './types';
|
||||||
|
|
||||||
const AGENT_IMAGE_MIME_TYPES = new Set<AgentImageMimeType>([
|
const AGENT_IMAGE_MIME_TYPES = new Set<AgentImageMimeType>([
|
||||||
|
|
@ -23,7 +22,7 @@ const OPTIMIZABLE_AGENT_IMAGE_MIME_TYPES = new Set<Exclude<AgentImageMimeType, '
|
||||||
'image/webp',
|
'image/webp',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const PROVIDER_IMAGE_MIME_TYPES = new Set<ProviderImageMimeType>([
|
const PROVIDER_IMAGE_MIME_TYPES = new Set<AgentImageMimeType>([
|
||||||
'image/png',
|
'image/png',
|
||||||
'image/jpeg',
|
'image/jpeg',
|
||||||
'image/gif',
|
'image/gif',
|
||||||
|
|
@ -34,8 +33,8 @@ export function isAgentImageMimeType(mimeType: string): mimeType is AgentImageMi
|
||||||
return AGENT_IMAGE_MIME_TYPES.has(mimeType as AgentImageMimeType);
|
return AGENT_IMAGE_MIME_TYPES.has(mimeType as AgentImageMimeType);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function isProviderImageMimeType(mimeType: string): mimeType is ProviderImageMimeType {
|
export function isProviderImageMimeType(mimeType: string): mimeType is AgentImageMimeType {
|
||||||
return PROVIDER_IMAGE_MIME_TYPES.has(mimeType as ProviderImageMimeType);
|
return PROVIDER_IMAGE_MIME_TYPES.has(mimeType as AgentImageMimeType);
|
||||||
}
|
}
|
||||||
|
|
||||||
function isOptimizableAgentImageMimeType(
|
function isOptimizableAgentImageMimeType(
|
||||||
|
|
@ -54,9 +53,9 @@ function isProviderFileMimeType(mimeType: string, supported: readonly string[]):
|
||||||
|
|
||||||
function isCapabilityImageMimeType(
|
function isCapabilityImageMimeType(
|
||||||
mimeType: string,
|
mimeType: string,
|
||||||
supported: readonly ProviderImageMimeType[]
|
supported: readonly AgentImageMimeType[]
|
||||||
): boolean {
|
): boolean {
|
||||||
return supported.includes(mimeType as ProviderImageMimeType);
|
return supported.includes(mimeType as AgentImageMimeType);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function classifyAttachmentMime(mimeType: string): AgentAttachmentKind {
|
export function classifyAttachmentMime(mimeType: string): AgentAttachmentKind {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue