-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathAltTextPluginConfig.ts
More file actions
113 lines (92 loc) · 3.61 KB
/
AltTextPluginConfig.ts
File metadata and controls
113 lines (92 loc) · 3.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import type { Field, PayloadRequest } from 'payload'
import type { AltTextResolver } from '../resolvers/types.js'
import type {
AltTextCollectionConfig,
IncomingCollectionsConfig,
NormalizedAltTextCollectionConfig,
} from '../utilities/mimeTypes.js'
export type { AltTextCollectionConfig, NormalizedAltTextCollectionConfig }
/** Configuration options for the alt text plugin. */
export type IncomingAltTextPluginConfig = {
/**
* Custom access control for plugin endpoints.
* Return `true` to allow access, `false` to deny.
*
* @default ({ req }) => !!req.user — requires authentication
*/
access?: (args: { req: PayloadRequest }) => boolean | Promise<boolean>
/**
* Collections to enable the plugin for.
*
* Each entry may be a bare collection slug or an object with a `slug` and an
* optional `mimeTypes` array restricting which MIME types are tracked,
* validated, and generated. Bare slugs default to `['image/*']`.
*
* @example
* ```typescript
* collections: [
* 'images', // shorthand — defaults to ['image/*']
* { slug: 'media', mimeTypes: ['image/*', 'application/pdf'] },
* ]
* ```
*/
collections: IncomingCollectionsConfig
/** Whether the plugin is enabled. */
enabled?: boolean
/** Override the default fields inserted by the plugin via a function that receives the default fields and returns the new fields */
fieldsOverride?: (args: { defaultFields: Field[] }) => Field[]
/**
* Function to get the thumbnail URL of an image document.
* This URL will be sent to the LLM for analysis.
*
* @remarks
* - The URL must be publicly accessible so the LLM can fetch it
* - Use a thumbnail/preview version of the image when possible (e.g. from the sizes field)
*/
getImageThumbnail: (doc: Record<string, unknown>) => string
/**
* Enable alt text health tracking (REST endpoint, cache revalidation hooks, and dashboard widget).
* Set to `false` to disable the entire feature.
*
* @default true
*/
healthCheck?: boolean
/**
* The locale to generate alt texts in when localization is disabled.
*
* Required when localization is disabled, ignored when localization is enabled.
* @example 'en'
*/
locale?: string
/**
* Maximum number of concurrent API requests for bulk generate operations.
*
* @default 16
*/
maxBulkGenerateConcurrency?: number
/** The resolver to use for generating alt text (e.g., openAIResolver) */
resolver: AltTextResolver
}
/** Configuration of the alt text plugin after defaults have been applied. */
export type AltTextPluginConfig = {
/** Access control for plugin endpoints. */
access: (args: { req: PayloadRequest }) => boolean | Promise<boolean>
/** Collections with resolved MIME type filters. */
collections: NormalizedAltTextCollectionConfig[]
/** Whether the plugin is enabled. */
enabled: boolean
/** Override the default fields inserted by the plugin via a function that receives the default fields and returns the new fields */
fieldsOverride?: (args: { defaultFields: Field[] }) => Field[]
/** Function to get the thumbnail URL of an image document. */
getImageThumbnail: (doc: Record<string, unknown>) => string
/** Whether alt text health tracking is enabled. */
healthCheck: boolean
/** The locale to generate alt texts in when localization is disabled. */
locale?: string
/** The locales to generate alt texts for. */
locales: string[]
/** Maximum number of concurrent API requests for bulk generate operations. */
maxBulkGenerateConcurrency: number
/** The resolver to use for generating alt text */
resolver: AltTextResolver
}