1import * as Schema from "effect/Schema";
2
3import { EnvironmentId, MessageId, ThreadId } from "./baseSchemas.ts";
4import { COMPOSER_CONTEXT_MAX_RECORDS, ComposerContextRecord } from "./composerContext.ts";
5import { ForwardCompatibleArray } from "./baseSchemas.ts";
6
7/**
8 * Structured clipboard payload for context copied between drafts and messages. Carries the
9 * records behind the copied links plus where they came from, never bytes or URLs; the receiver
10 * resolves binaries through its own environment.
11 */
12export const COMPOSER_CONTEXT_CLIPBOARD_MIME = "web application/x-t3-context-fragment+json";
13
14export const ComposerContextClipboardFragment = Schema.Struct({
15 version: Schema.Literal(1),
16 source: Schema.Struct({
17 environmentId: EnvironmentId,
18 threadId: Schema.optional(ThreadId),
19 messageId: Schema.optional(MessageId),
20 }),
21 // The bound applies to the raw input, as in `OrchestrationMessageContext`: forward-compatible
22 // decoding drops unknown records first, so a checked output length never sees the flood.
23 records: Schema.Array(Schema.Unknown)
24 .check(Schema.isMaxLength(COMPOSER_CONTEXT_MAX_RECORDS))
25 .pipe(Schema.decodeTo(ForwardCompatibleArray(ComposerContextRecord))),
26});
27export type ComposerContextClipboardFragment = typeof ComposerContextClipboardFragment.Type;