Open History to see the last commit
1import * as Schema from "effect/Schema";
2
3import { MessageId, NonNegativeInt, ThreadId, TrimmedNonEmptyString } from "./baseSchemas.ts";
4
5export const PROVIDER_SEND_TURN_MAX_INPUT_CHARS = 120_000;
6export const PROVIDER_SEND_TURN_MAX_ATTACHMENTS = 8;
7export const PROVIDER_SEND_TURN_MAX_IMAGE_BYTES = 10 * 1024 * 1024;
8const PROVIDER_SEND_TURN_MAX_IMAGE_DATA_URL_CHARS = 14_000_000;
9const CHAT_ATTACHMENT_ID_MAX_CHARS = 128;
10
11export const ChatAttachmentId = TrimmedNonEmptyString.check(
12 Schema.isMaxLength(CHAT_ATTACHMENT_ID_MAX_CHARS),
13 Schema.isPattern(/^[a-z0-9_-]+$/i),
14);
15export type ChatAttachmentId = typeof ChatAttachmentId.Type;
16
17export const ChatImageAttachment = Schema.Struct({
18 type: Schema.Literal("image"),
19 id: ChatAttachmentId,
20 name: TrimmedNonEmptyString.check(Schema.isMaxLength(255)),
21 mimeType: TrimmedNonEmptyString.check(Schema.isMaxLength(100), Schema.isPattern(/^image\//i)),
22 sizeBytes: NonNegativeInt.check(Schema.isLessThanOrEqualTo(PROVIDER_SEND_TURN_MAX_IMAGE_BYTES)),
23});
24export type ChatImageAttachment = typeof ChatImageAttachment.Type;
25
26export const UploadChatImageAttachment = Schema.Struct({
27 type: Schema.Literal("image"),
28 name: TrimmedNonEmptyString.check(Schema.isMaxLength(255)),
29 mimeType: TrimmedNonEmptyString.check(Schema.isMaxLength(100), Schema.isPattern(/^image\//i)),
30 sizeBytes: NonNegativeInt.check(Schema.isLessThanOrEqualTo(PROVIDER_SEND_TURN_MAX_IMAGE_BYTES)),
31 dataUrl: TrimmedNonEmptyString.check(
32 Schema.isMaxLength(PROVIDER_SEND_TURN_MAX_IMAGE_DATA_URL_CHARS),
33 ),
34});
35export type UploadChatImageAttachment = typeof UploadChatImageAttachment.Type;
36
37export const ChatAttachment = Schema.Union([ChatImageAttachment]);
38export type ChatAttachment = typeof ChatAttachment.Type;
39
40export const UploadChatAttachment = Schema.Union([UploadChatImageAttachment]);
41export type UploadChatAttachment = typeof UploadChatAttachment.Type;
42
43export const PersistChatAttachmentsInput = Schema.Struct({
44 threadId: ThreadId,
45 messageId: MessageId,
46 attachments: Schema.Array(UploadChatAttachment),
47});
48export type PersistChatAttachmentsInput = typeof PersistChatAttachmentsInput.Type;
49
50export const PersistChatAttachmentsResult = Schema.Struct({
51 attachments: Schema.Array(ChatAttachment),
52});
53export type PersistChatAttachmentsResult = typeof PersistChatAttachmentsResult.Type;
54
55export class PersistChatAttachmentsError extends Schema.TaggedErrorClass<PersistChatAttachmentsError>()(
56 "PersistChatAttachmentsError",
57 {
58 message: Schema.String,
59 cause: Schema.optional(Schema.Defect()),
60 },
61) {}