@@ -15,7 +15,11 @@ import {
1515import { privateSecretProvenanceBundleSchema } from '@/lib/api/contracts/primitives'
1616import { defineRouteContract } from '@/lib/api/contracts/types'
1717import { PRIVATE_SECRET_PROVENANCE_FIELD } from '@/lib/execution/private-tool-metadata'
18- import { getFieldTypeForSlot , MAX_KNOWLEDGE_DOCUMENTS_PER_CREATE } from '@/lib/knowledge/constants'
18+ import {
19+ getFieldTypeForSlot ,
20+ MAX_DOCUMENT_INDEXED_TEXT_LENGTH ,
21+ MAX_KNOWLEDGE_DOCUMENTS_PER_CREATE ,
22+ } from '@/lib/knowledge/constants'
1923import { DOCUMENT_PROCESSING_STATUSES } from '@/lib/knowledge/documents/types'
2024import { getOperatorsForFieldType , isValidFilterValue } from '@/lib/knowledge/filters/types'
2125import { knowledgeDocumentUploadMetadataSchema } from '@/lib/knowledge/upload-metadata'
@@ -115,18 +119,32 @@ export function parseDocumentTagFiltersParam(
115119 return z . array ( documentTagFilterSchema ) . parse ( JSON . parse ( value ) )
116120}
117121
122+ /** A text tag value that fits its index row; see {@link MAX_DOCUMENT_INDEXED_TEXT_LENGTH}. */
123+ const documentTagValueSchema = z
124+ . string ( )
125+ . max (
126+ MAX_DOCUMENT_INDEXED_TEXT_LENGTH ,
127+ `Tag values cannot exceed ${ MAX_DOCUMENT_INDEXED_TEXT_LENGTH } characters`
128+ )
129+
118130export const createDocumentBodySchema = z . object ( {
119- filename : z . string ( ) . min ( 1 , 'Filename is required' ) ,
131+ filename : z
132+ . string ( )
133+ . min ( 1 , 'Filename is required' )
134+ . max (
135+ MAX_DOCUMENT_INDEXED_TEXT_LENGTH ,
136+ `Filename cannot exceed ${ MAX_DOCUMENT_INDEXED_TEXT_LENGTH } characters`
137+ ) ,
120138 fileUrl : knowledgeDocumentFileUrlSchema ,
121139 fileSize : z . number ( ) . min ( 1 , 'File size must be greater than 0' ) ,
122140 mimeType : z . string ( ) . min ( 1 , 'MIME type is required' ) ,
123- tag1 : z . string ( ) . optional ( ) ,
124- tag2 : z . string ( ) . optional ( ) ,
125- tag3 : z . string ( ) . optional ( ) ,
126- tag4 : z . string ( ) . optional ( ) ,
127- tag5 : z . string ( ) . optional ( ) ,
128- tag6 : z . string ( ) . optional ( ) ,
129- tag7 : z . string ( ) . optional ( ) ,
141+ tag1 : documentTagValueSchema . optional ( ) ,
142+ tag2 : documentTagValueSchema . optional ( ) ,
143+ tag3 : documentTagValueSchema . optional ( ) ,
144+ tag4 : documentTagValueSchema . optional ( ) ,
145+ tag5 : documentTagValueSchema . optional ( ) ,
146+ tag6 : documentTagValueSchema . optional ( ) ,
147+ tag7 : documentTagValueSchema . optional ( ) ,
130148 documentTagsData : z . string ( ) . optional ( ) ,
131149} )
132150
@@ -165,7 +183,13 @@ export type SingleCreateDocumentBody = z.input<typeof singleCreateDocumentBodySc
165183
166184export const upsertDocumentBodySchema = z . object ( {
167185 documentId : z . string ( ) . optional ( ) ,
168- filename : z . string ( ) . min ( 1 , 'Filename is required' ) ,
186+ filename : z
187+ . string ( )
188+ . min ( 1 , 'Filename is required' )
189+ . max (
190+ MAX_DOCUMENT_INDEXED_TEXT_LENGTH ,
191+ `Filename cannot exceed ${ MAX_DOCUMENT_INDEXED_TEXT_LENGTH } characters`
192+ ) ,
169193 fileUrl : knowledgeDocumentFileUrlSchema ,
170194 fileSize : z . number ( ) . min ( 1 , 'File size must be greater than 0' ) ,
171195 mimeType : z . string ( ) . min ( 1 , 'MIME type is required' ) ,
@@ -196,7 +220,14 @@ export const bulkCreateDocumentsResponseSchema = z.object({
196220} )
197221
198222export const updateDocumentBodySchema = z . object ( {
199- filename : z . string ( ) . min ( 1 , 'Filename is required' ) . optional ( ) ,
223+ filename : z
224+ . string ( )
225+ . min ( 1 , 'Filename is required' )
226+ . max (
227+ MAX_DOCUMENT_INDEXED_TEXT_LENGTH ,
228+ `Filename cannot exceed ${ MAX_DOCUMENT_INDEXED_TEXT_LENGTH } characters`
229+ )
230+ . optional ( ) ,
200231 enabled : z . boolean ( ) . optional ( ) ,
201232 chunkCount : z . number ( ) . min ( 0 ) . optional ( ) ,
202233 tokenCount : z . number ( ) . min ( 0 ) . optional ( ) ,
@@ -205,13 +236,13 @@ export const updateDocumentBodySchema = z.object({
205236 processingError : z . string ( ) . optional ( ) ,
206237 markFailedDueToTimeout : z . boolean ( ) . optional ( ) ,
207238 retryProcessing : z . boolean ( ) . optional ( ) ,
208- tag1 : z . string ( ) . optional ( ) ,
209- tag2 : z . string ( ) . optional ( ) ,
210- tag3 : z . string ( ) . optional ( ) ,
211- tag4 : z . string ( ) . optional ( ) ,
212- tag5 : z . string ( ) . optional ( ) ,
213- tag6 : z . string ( ) . optional ( ) ,
214- tag7 : z . string ( ) . optional ( ) ,
239+ tag1 : documentTagValueSchema . optional ( ) ,
240+ tag2 : documentTagValueSchema . optional ( ) ,
241+ tag3 : documentTagValueSchema . optional ( ) ,
242+ tag4 : documentTagValueSchema . optional ( ) ,
243+ tag5 : documentTagValueSchema . optional ( ) ,
244+ tag6 : documentTagValueSchema . optional ( ) ,
245+ tag7 : documentTagValueSchema . optional ( ) ,
215246 number1 : z . string ( ) . optional ( ) ,
216247 number2 : z . string ( ) . optional ( ) ,
217248 number3 : z . string ( ) . optional ( ) ,
0 commit comments