| 1 | import * as Schema from "effect/Schema"; |
| 2 | import { EnvironmentId, MessageId, NonNegativeInt, ThreadId } from "./baseSchemas.ts"; |
| 3 | |
| 4 | export const ASSISTANT_CITATION_MAX_TEXT_LENGTH = 8_000; |
| 5 | export const ASSISTANT_CITATION_MAX_COMMENT_LENGTH = 8_000; |
| 6 | export const ASSISTANT_CITATION_CONTEXT_LENGTH = 32; |
| 7 | |
| 8 | /** |
| 9 | * A quote of rendered assistant text with an optional user comment. |
| 10 | * Positions are UTF-16 offsets, not Markdown offsets. |
| 11 | */ |
| 12 | export const AssistantCitation = Schema.Struct({ |
| 13 | version: Schema.Literal(1), |
| 14 | environmentId: EnvironmentId.check(Schema.isMaxLength(512)), |
| 15 | threadId: ThreadId.check(Schema.isMaxLength(512)), |
| 16 | messageId: MessageId.check(Schema.isMaxLength(512)), |
| 17 | text: Schema.String.check( |
| 18 | Schema.isNonEmpty(), |
| 19 | Schema.isMaxLength(ASSISTANT_CITATION_MAX_TEXT_LENGTH), |
| 20 | ), |
| 21 | comment: Schema.optional( |
| 22 | Schema.String.check(Schema.isMaxLength(ASSISTANT_CITATION_MAX_COMMENT_LENGTH)), |
| 23 | ), |
| 24 | start: NonNegativeInt.check(Schema.isLessThanOrEqualTo(Number.MAX_SAFE_INTEGER)), |
| 25 | end: NonNegativeInt.check(Schema.isLessThanOrEqualTo(Number.MAX_SAFE_INTEGER)), |
| 26 | prefix: Schema.String.check(Schema.isMaxLength(ASSISTANT_CITATION_CONTEXT_LENGTH)), |
| 27 | suffix: Schema.String.check(Schema.isMaxLength(ASSISTANT_CITATION_CONTEXT_LENGTH)), |
| 28 | }).check( |
| 29 | Schema.makeFilter((citation) => citation.end > citation.start && citation.text.trim().length > 0), |
| 30 | ); |
| 31 | export type AssistantCitation = typeof AssistantCitation.Type; |