@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 03:37 UTC

main
ts 30 lines 1.58 KB
Raw
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 // Provider message IDs nest and re-encode their thread and turn IDs, so they outgrow a few hundred characters.
8 export const ASSISTANT_CITATION_MAX_ID_LENGTH = 4_096;
9
10 /** Positions are UTF-16 offsets, not Markdown offsets. */
11 export const AssistantCitation = Schema.Struct({
12 version: Schema.Literal(1),
13 environmentId: EnvironmentId.check(Schema.isMaxLength(ASSISTANT_CITATION_MAX_ID_LENGTH)),
14 threadId: ThreadId.check(Schema.isMaxLength(ASSISTANT_CITATION_MAX_ID_LENGTH)),
15 messageId: MessageId.check(Schema.isMaxLength(ASSISTANT_CITATION_MAX_ID_LENGTH)),
16 text: Schema.String.check(
17 Schema.isNonEmpty(),
18 Schema.isMaxLength(ASSISTANT_CITATION_MAX_TEXT_LENGTH),
19 ),
20 comment: Schema.optional(
21 Schema.String.check(Schema.isMaxLength(ASSISTANT_CITATION_MAX_COMMENT_LENGTH)),
22 ),
23 start: NonNegativeInt.check(Schema.isLessThanOrEqualTo(Number.MAX_SAFE_INTEGER)),
24 end: NonNegativeInt.check(Schema.isLessThanOrEqualTo(Number.MAX_SAFE_INTEGER)),
25 prefix: Schema.String.check(Schema.isMaxLength(ASSISTANT_CITATION_CONTEXT_LENGTH)),
26 suffix: Schema.String.check(Schema.isMaxLength(ASSISTANT_CITATION_CONTEXT_LENGTH)),
27 }).check(
28 Schema.makeFilter((citation) => citation.end > citation.start && citation.text.trim().length > 0),
29 );
30 export type AssistantCitation = typeof AssistantCitation.Type;