Something went wrong. Try again.
A monorepo for writing specs and other serious text on the AT Protocol.
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667// What a host tells draft about itself: who is writing, which blocks exist// in this context, where references come from, how images are stored, and// which assistant (if any) sits in the sidebar.import type { Extensions } from '@tiptap/core';import type * as Y from 'yjs';import type { Assistant } from './assistant/types.ts';import type { CountLine, Counts } from './count.ts';
/** Block types beyond the paragraph; a host enables the ones that make sense for it. */export type BlockKind = 'list' | 'ordered' | 'code' | 'math' | 'definitionList' | 'figure' | 'section';
export const ALL_BLOCKS: readonly BlockKind[] = ['list', 'ordered', 'code', 'math', 'definitionList', 'figure', 'section'];
export type Author = { id: string; name: string; kind: 'human' | 'assistant';};
/** A citable reference, as the "[" menu (and a host's imports picker) shows it. */export type RefItem = { key: string; title?: string; href?: string; hint?: string };
/** A term defined by an imported reference, as the "@" menu shows it. */export type TermItem = { text: string; ref: string; href: string; hint?: string };
export type ReferenceProvider = { /** Catalogue entries matching q. */ searchRefs?: (q: string) => Promise<RefItem[]>; /** Terms of the imported references matching q. */ searchTerms?: (q: string) => Promise<TermItem[]>;};
export type UploadedFile = { cid: string; mimeType: string; size: number };
/** Something the assistant may read but not edit: another chapter, a note the writer attached. */export type ContextItem = { label: string; text: string };
/** ProseMirror JSON. */export type PMMark = { type: string; attrs?: Record<string, unknown> };export type PMJson = { type: string; attrs?: Record<string, unknown>; content?: PMJson[]; text?: string; marks?: PMMark[] };
export type DraftConfig = { author: Author; /** Which block types this host offers (paragraphs are always there). Default: all. */ blocks?: readonly BlockKind[]; /** Extra TipTap extensions from the host (its own block types, say). */ extensions?: Extensions; references?: ReferenceProvider; /** Store an image; without it the figure block only takes a caption. */ upload?: (file: File) => Promise<UploadedFile>; /** The URL of a stored image. */ blobUrl?: (cid: string) => string; assistant?: Assistant; /** Material that goes to the assistant beside the document, for context only (other chapters, attached notes); asked for at each turn. */ context?: () => ContextItem[]; /** Share the document (and the suggestions' metadata) through a Yjs document. */ collaboration?: { doc: Y.Doc; field?: string }; /** Mint ids for new blocks and sections (hosts with their own key format pass theirs). */ generateId?: () => string; /** Called after every change with the whole document. */ onChange?: (json: PMJson) => void; /** Whether edits are suggestions to begin with. */ suggesting?: boolean; /** The count note at the bottom left of the screen: `false` for none, or the lines to show given this text's live words and characters (a host with chapters adds the whole). Default: the text's own. */ counts?: false | ((live: Counts) => CountLine[]);};