import { z } from 'zod'; import { SOURCE_ORIGIN, SOURCE_STATUS, SOURCE_TYPE } from '../constants'; export const BookBibliographicMetadataSchema = z .object({ type: z.literal(SOURCE_TYPE.BOOK), title: z.string().describe('Title of the book'), authors: z.string().describe('Authors of the book'), year: z.number().int().describe('Year of publication of the book'), publicationCity: z.string().describe('City of publication of the book'), publisher: z.string().describe('Publisher of the book'), pageCount: z.number().int().nullable().describe('Page count of the book'), }) .describe( 'Format: Фамилия, И.О. Название книги / И.О. Фамилия. — Город: Издательство, Год. — Количество с.', ); export type BookBibliographicMetadata = z.infer; export const JournalArticleBibliographicMetadataSchema = z .object({ type: z.literal(SOURCE_TYPE.JOURNAL_ARTICLE), title: z.string().describe('Title of the journal article'), authors: z.string().describe('Authors of the journal article'), year: z.number().int().describe('Year of publication of the journal article'), journalName: z.string().describe('Name of the journal'), issueNumber: z.string().describe('Issue number of the journal article'), pageRange: z.string().describe('Page range of the journal article'), volume: z.string().optional().describe('Volume of the journal article, optional'), }) .describe( 'Format: Фамилия, И.О. Название статьи / И.О. Фамилия // Название журнала. — Год. — Том. — № номер. — С. страницы.', ); export type JournalArticleBibliographicMetadata = z.infer< typeof JournalArticleBibliographicMetadataSchema >; export const SourceBibliographicMetadataSchema = z.discriminatedUnion('type', [ BookBibliographicMetadataSchema, JournalArticleBibliographicMetadataSchema, ]); export type SourceBibliographicMetadata = z.infer; export const WriterSourceSchema = z.object({ uuid: z.string().uuid(), url: z.string().url().describe('URL of the file'), title: z.string().nullable().describe('Title of the source'), type: z.nativeEnum(SOURCE_TYPE).nullable().describe('Type of the source for citation'), sourceOrigin: z .nativeEnum(SOURCE_ORIGIN) .describe('Origin of the source, either internal WEB_SEARCH or USER_UPLOAD'), citation: z .string() .nullable() .describe('Citation text that will appear at the end of the document'), status: z .nativeEnum(SOURCE_STATUS) .describe('Status of the source, only READY sources are used during content generation'), bibliographicMetadata: SourceBibliographicMetadataSchema.nullable().describe( 'Bibliographic metadata of the source, used for building citations at the end of the document', ), createdAt: z.date().describe('Creation date of the source'), updatedAt: z.date().describe('Update date of the source'), }); export type WriterSource = z.infer;