@@ -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,26 @@ 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 ( MAX_DOCUMENT_INDEXED_TEXT_LENGTH , `Tag values cannot exceed ${ MAX_DOCUMENT_INDEXED_TEXT_LENGTH } characters` )
126+
118127export const createDocumentBodySchema = z . object ( {
119- filename : z . string ( ) . min ( 1 , 'Filename is required' ) ,
128+ filename : z
129+ . string ( )
130+ . min ( 1 , 'Filename is required' )
131+ . max ( MAX_DOCUMENT_INDEXED_TEXT_LENGTH , `Filename cannot exceed ${ MAX_DOCUMENT_INDEXED_TEXT_LENGTH } characters` ) ,
120132 fileUrl : knowledgeDocumentFileUrlSchema ,
121133 fileSize : z . number ( ) . min ( 1 , 'File size must be greater than 0' ) ,
122134 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 ( ) ,
135+ tag1 : documentTagValueSchema . optional ( ) ,
136+ tag2 : documentTagValueSchema . optional ( ) ,
137+ tag3 : documentTagValueSchema . optional ( ) ,
138+ tag4 : documentTagValueSchema . optional ( ) ,
139+ tag5 : documentTagValueSchema . optional ( ) ,
140+ tag6 : documentTagValueSchema . optional ( ) ,
141+ tag7 : documentTagValueSchema . optional ( ) ,
130142 documentTagsData : z . string ( ) . optional ( ) ,
131143} )
132144
@@ -165,7 +177,10 @@ export type SingleCreateDocumentBody = z.input<typeof singleCreateDocumentBodySc
165177
166178export const upsertDocumentBodySchema = z . object ( {
167179 documentId : z . string ( ) . optional ( ) ,
168- filename : z . string ( ) . min ( 1 , 'Filename is required' ) ,
180+ filename : z
181+ . string ( )
182+ . min ( 1 , 'Filename is required' )
183+ . max ( MAX_DOCUMENT_INDEXED_TEXT_LENGTH , `Filename cannot exceed ${ MAX_DOCUMENT_INDEXED_TEXT_LENGTH } characters` ) ,
169184 fileUrl : knowledgeDocumentFileUrlSchema ,
170185 fileSize : z . number ( ) . min ( 1 , 'File size must be greater than 0' ) ,
171186 mimeType : z . string ( ) . min ( 1 , 'MIME type is required' ) ,
@@ -196,7 +211,10 @@ export const bulkCreateDocumentsResponseSchema = z.object({
196211} )
197212
198213export const updateDocumentBodySchema = z . object ( {
199- filename : z . string ( ) . min ( 1 , 'Filename is required' ) . optional ( ) ,
214+ filename : z
215+ . string ( )
216+ . min ( 1 , 'Filename is required' )
217+ . max ( MAX_DOCUMENT_INDEXED_TEXT_LENGTH , `Filename cannot exceed ${ MAX_DOCUMENT_INDEXED_TEXT_LENGTH } characters` ) . optional ( ) ,
200218 enabled : z . boolean ( ) . optional ( ) ,
201219 chunkCount : z . number ( ) . min ( 0 ) . optional ( ) ,
202220 tokenCount : z . number ( ) . min ( 0 ) . optional ( ) ,
@@ -205,13 +223,13 @@ export const updateDocumentBodySchema = z.object({
205223 processingError : z . string ( ) . optional ( ) ,
206224 markFailedDueToTimeout : z . boolean ( ) . optional ( ) ,
207225 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 ( ) ,
226+ tag1 : documentTagValueSchema . optional ( ) ,
227+ tag2 : documentTagValueSchema . optional ( ) ,
228+ tag3 : documentTagValueSchema . optional ( ) ,
229+ tag4 : documentTagValueSchema . optional ( ) ,
230+ tag5 : documentTagValueSchema . optional ( ) ,
231+ tag6 : documentTagValueSchema . optional ( ) ,
232+ tag7 : documentTagValueSchema . optional ( ) ,
215233 number1 : z . string ( ) . optional ( ) ,
216234 number2 : z . string ( ) . optional ( ) ,
217235 number3 : z . string ( ) . optional ( ) ,
0 commit comments