@copilotkit/markdown 0.0.1 → 2.0.0-rc.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,361 @@
1
+ //#region src/parser/types.d.ts
2
+ type SegmentGranularity = "grapheme" | "word" | "sentence";
3
+ /**
4
+ * Segmenter configuration for parse-time text segmentation.
5
+ * @public
6
+ */
7
+ type SegmenterOptions = false | true | {
8
+ locale?: string;
9
+ granularity?: SegmentGranularity;
10
+ };
11
+ /**
12
+ * Options for the streaming markdown parser.
13
+ * @public
14
+ */
15
+ type StreamingMarkdownParserOptions = {
16
+ segmenter: SegmenterOptions;
17
+ enableTables: boolean;
18
+ enableAutolinks: boolean;
19
+ };
20
+ /**
21
+ * Supported streaming markdown AST node kinds.
22
+ * @public
23
+ */
24
+ type StreamingMarkdownNodeType = "document" | "paragraph" | "heading" | "blockquote" | "list" | "list-item" | "code-block" | "table" | "table-row" | "table-cell" | "thematic-break" | "text" | "em" | "strong" | "strikethrough" | "inline-code" | "soft-break" | "hard-break" | "image" | "link" | "autolink" | "citation";
25
+ /**
26
+ * Parsing mode for block-level processing.
27
+ * @public
28
+ */
29
+ type ParseMode = "block" | "paragraph" | "heading" | "blockquote" | "list-item" | "code-fence" | "table";
30
+ /**
31
+ * Parser warning variants.
32
+ * @public
33
+ */
34
+ type StreamingMarkdownWarning = {
35
+ code: "unterminated_construct";
36
+ kind: string;
37
+ at: number;
38
+ } | {
39
+ code: "invalid_citation_definition";
40
+ at: number;
41
+ } | {
42
+ code: "unmatched_closer";
43
+ token: string;
44
+ at: number;
45
+ } | {
46
+ code: "segmenter_unavailable";
47
+ at: number;
48
+ } | {
49
+ code: "unknown_construct";
50
+ at: number;
51
+ };
52
+ /**
53
+ * Parse-time text segment for animation-friendly rendering.
54
+ * @public
55
+ */
56
+ type TextSegment = {
57
+ text: string;
58
+ start: number;
59
+ end: number;
60
+ kind: SegmentGranularity;
61
+ isWhitespace: boolean;
62
+ /**
63
+ * Hint for renderers to avoid line-breaking before this segment.
64
+ * @public
65
+ */
66
+ noBreakBefore?: boolean;
67
+ };
68
+ /**
69
+ * Shared fields on all AST nodes.
70
+ * @public
71
+ */
72
+ type StreamingMarkdownAstNodeBase = {
73
+ id: number;
74
+ type: StreamingMarkdownNodeType;
75
+ parentId: number | null;
76
+ closed: boolean;
77
+ range: {
78
+ start: number;
79
+ end: number;
80
+ };
81
+ };
82
+ /**
83
+ * AST node representing the document root.
84
+ * @public
85
+ */
86
+ type StreamingMarkdownDocumentNode = StreamingMarkdownAstNodeBase & {
87
+ type: "document";
88
+ children: number[];
89
+ };
90
+ /**
91
+ * AST node representing a paragraph.
92
+ * @public
93
+ */
94
+ type StreamingMarkdownParagraphNode = StreamingMarkdownAstNodeBase & {
95
+ type: "paragraph";
96
+ children: number[];
97
+ };
98
+ /**
99
+ * AST node representing a heading.
100
+ * @public
101
+ */
102
+ type StreamingMarkdownHeadingNode = StreamingMarkdownAstNodeBase & {
103
+ type: "heading";
104
+ level: 1 | 2 | 3 | 4 | 5 | 6;
105
+ children: number[];
106
+ };
107
+ /**
108
+ * AST node representing a blockquote.
109
+ * @public
110
+ */
111
+ type StreamingMarkdownBlockquoteNode = StreamingMarkdownAstNodeBase & {
112
+ type: "blockquote";
113
+ children: number[];
114
+ };
115
+ /**
116
+ * AST node representing a list.
117
+ * @public
118
+ */
119
+ type StreamingMarkdownListNode = StreamingMarkdownAstNodeBase & {
120
+ type: "list";
121
+ ordered: boolean;
122
+ start: number | null;
123
+ tight: boolean;
124
+ children: number[];
125
+ };
126
+ /**
127
+ * AST node representing a list item.
128
+ * @public
129
+ */
130
+ type StreamingMarkdownListItemNode = StreamingMarkdownAstNodeBase & {
131
+ type: "list-item";
132
+ children: number[];
133
+ };
134
+ /**
135
+ * AST node representing a fenced code block.
136
+ * @public
137
+ */
138
+ type StreamingMarkdownCodeBlockNode = StreamingMarkdownAstNodeBase & {
139
+ type: "code-block";
140
+ fence: "```" | "~~~";
141
+ info?: string;
142
+ meta?: string;
143
+ text: string;
144
+ };
145
+ /**
146
+ * AST node representing a table.
147
+ * @public
148
+ */
149
+ type StreamingMarkdownTableNode = StreamingMarkdownAstNodeBase & {
150
+ type: "table";
151
+ align: Array<"left" | "right" | "center" | "none">;
152
+ children: number[];
153
+ };
154
+ /**
155
+ * AST node representing a table row.
156
+ * @public
157
+ */
158
+ type StreamingMarkdownTableRowNode = StreamingMarkdownAstNodeBase & {
159
+ type: "table-row";
160
+ isHeader: boolean;
161
+ children: number[];
162
+ };
163
+ /**
164
+ * AST node representing a table cell.
165
+ * @public
166
+ */
167
+ type StreamingMarkdownTableCellNode = StreamingMarkdownAstNodeBase & {
168
+ type: "table-cell";
169
+ children: number[];
170
+ };
171
+ /**
172
+ * AST node representing a thematic break.
173
+ * @public
174
+ */
175
+ type StreamingMarkdownThematicBreakNode = StreamingMarkdownAstNodeBase & {
176
+ type: "thematic-break";
177
+ };
178
+ /**
179
+ * AST node representing a text run.
180
+ * @public
181
+ */
182
+ type StreamingMarkdownTextNode = StreamingMarkdownAstNodeBase & {
183
+ type: "text";
184
+ text: string;
185
+ segments: TextSegment[];
186
+ };
187
+ /**
188
+ * AST node representing emphasis.
189
+ * @public
190
+ */
191
+ type StreamingMarkdownEmphasisNode = StreamingMarkdownAstNodeBase & {
192
+ type: "em";
193
+ children: number[];
194
+ };
195
+ /**
196
+ * AST node representing strong emphasis.
197
+ * @public
198
+ */
199
+ type StreamingMarkdownStrongNode = StreamingMarkdownAstNodeBase & {
200
+ type: "strong";
201
+ children: number[];
202
+ };
203
+ /**
204
+ * AST node representing strikethrough.
205
+ * @public
206
+ */
207
+ type StreamingMarkdownStrikethroughNode = StreamingMarkdownAstNodeBase & {
208
+ type: "strikethrough";
209
+ children: number[];
210
+ };
211
+ /**
212
+ * AST node representing inline code.
213
+ * @public
214
+ */
215
+ type StreamingMarkdownInlineCodeNode = StreamingMarkdownAstNodeBase & {
216
+ type: "inline-code";
217
+ text: string;
218
+ };
219
+ /**
220
+ * AST node representing a soft line break.
221
+ * @public
222
+ */
223
+ type StreamingMarkdownSoftBreakNode = StreamingMarkdownAstNodeBase & {
224
+ type: "soft-break";
225
+ };
226
+ /**
227
+ * AST node representing a hard line break.
228
+ * @public
229
+ */
230
+ type StreamingMarkdownHardBreakNode = StreamingMarkdownAstNodeBase & {
231
+ type: "hard-break";
232
+ };
233
+ /**
234
+ * AST node representing a link.
235
+ * @public
236
+ */
237
+ type StreamingMarkdownLinkNode = StreamingMarkdownAstNodeBase & {
238
+ type: "link";
239
+ url: string;
240
+ title?: string;
241
+ children: number[];
242
+ };
243
+ /**
244
+ * AST node representing an image.
245
+ * @public
246
+ */
247
+ type StreamingMarkdownImageNode = StreamingMarkdownAstNodeBase & {
248
+ type: "image";
249
+ url: string;
250
+ title?: string;
251
+ alt: string;
252
+ };
253
+ /**
254
+ * AST node representing an autolink.
255
+ * @public
256
+ */
257
+ type StreamingMarkdownAutolinkNode = StreamingMarkdownAstNodeBase & {
258
+ type: "autolink";
259
+ url: string;
260
+ text: string;
261
+ };
262
+ /**
263
+ * AST node representing a citation reference.
264
+ * @public
265
+ */
266
+ type StreamingMarkdownCitationNode = StreamingMarkdownAstNodeBase & {
267
+ type: "citation";
268
+ idRef: string;
269
+ number?: number;
270
+ };
271
+ /**
272
+ * Union of all AST node shapes.
273
+ * @public
274
+ */
275
+ type StreamingMarkdownAstNode = StreamingMarkdownDocumentNode | StreamingMarkdownParagraphNode | StreamingMarkdownHeadingNode | StreamingMarkdownBlockquoteNode | StreamingMarkdownListNode | StreamingMarkdownListItemNode | StreamingMarkdownCodeBlockNode | StreamingMarkdownTableNode | StreamingMarkdownTableRowNode | StreamingMarkdownTableCellNode | StreamingMarkdownThematicBreakNode | StreamingMarkdownTextNode | StreamingMarkdownEmphasisNode | StreamingMarkdownStrongNode | StreamingMarkdownStrikethroughNode | StreamingMarkdownInlineCodeNode | StreamingMarkdownSoftBreakNode | StreamingMarkdownHardBreakNode | StreamingMarkdownImageNode | StreamingMarkdownLinkNode | StreamingMarkdownAutolinkNode | StreamingMarkdownCitationNode;
276
+ /**
277
+ * Citation definition captured during parsing.
278
+ * @public
279
+ */
280
+ type CitationDefinition = {
281
+ id: string;
282
+ text: string;
283
+ url?: string;
284
+ };
285
+ /**
286
+ * Citation parser state.
287
+ * @public
288
+ */
289
+ type CitationState = {
290
+ order: string[];
291
+ numbers: Record<string, number>;
292
+ definitions: Record<string, CitationDefinition>;
293
+ };
294
+ /**
295
+ * Immutable state for streaming markdown parsing.
296
+ * @public
297
+ */
298
+ type StreamingMarkdownParserState = {
299
+ nextId: number;
300
+ nodes: StreamingMarkdownAstNode[];
301
+ rootId: number | null;
302
+ stack: number[];
303
+ mode: ParseMode;
304
+ warnings: StreamingMarkdownWarning[];
305
+ citations: CitationState;
306
+ lineBuffer: string;
307
+ isComplete: boolean;
308
+ index: number;
309
+ line: number;
310
+ column: number;
311
+ options: StreamingMarkdownParserOptions;
312
+ source: string;
313
+ pathToId: Record<string, number>;
314
+ pendingCarriageReturn: boolean;
315
+ hasWarnedSegmenterUnavailable: boolean;
316
+ };
317
+ //#endregion
318
+ //#region src/parser/state.d.ts
319
+ /**
320
+ * Creates a new streaming markdown parser state.
321
+ *
322
+ * @param options - Optional parser option overrides.
323
+ * @returns New immutable parser state.
324
+ * @public
325
+ */
326
+ declare function createStreamingMarkdownParserState(options?: Partial<StreamingMarkdownParserOptions>): StreamingMarkdownParserState;
327
+ /**
328
+ * Parses a streaming chunk and returns the next immutable parser state.
329
+ *
330
+ * @param state - Current parser state.
331
+ * @param chunk - Incoming text chunk.
332
+ * @returns Updated parser state.
333
+ * @public
334
+ */
335
+ declare function parseStreamingMarkdownChunk(state: StreamingMarkdownParserState, chunk: string): StreamingMarkdownParserState;
336
+ /**
337
+ * Finalizes parsing by closing any provisional nodes and flushing trailing CR.
338
+ *
339
+ * @param state - Current parser state.
340
+ * @returns Final parser state.
341
+ * @public
342
+ */
343
+ declare function finalizeStreamingMarkdown(state: StreamingMarkdownParserState): StreamingMarkdownParserState;
344
+ //#endregion
345
+ //#region src/dev-warning.d.ts
346
+ /**
347
+ * Dev-only, once-per-session warning emitted when CopilotKit's built-in default
348
+ * markdown renderer encounters markdown it won't render richly — math
349
+ * (`$$…$$` / `\[…\]`) or a language-tagged fenced code block (rendered as plain,
350
+ * un-highlighted code). Helps people upgrading from the bundled Streamdown
351
+ * default notice the behavioral change and points them at the migration guide.
352
+ *
353
+ * No-op in production and after the first warning. Only the built-in default
354
+ * renderers call this — a custom `markdownRenderer` never triggers it.
355
+ *
356
+ * @internal
357
+ */
358
+ declare function warnUnsupportedRichSyntaxOnce(content: string): void;
359
+ //#endregion
360
+ export { type CitationDefinition, type CitationState, type ParseMode, type SegmenterOptions, type StreamingMarkdownAstNode, type StreamingMarkdownNodeType, type StreamingMarkdownParserOptions, type StreamingMarkdownParserState, type StreamingMarkdownWarning, type TextSegment, createStreamingMarkdownParserState, finalizeStreamingMarkdown, parseStreamingMarkdownChunk, warnUnsupportedRichSyntaxOnce };
361
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/parser/types.ts","../src/parser/state.ts","../src/dev-warning.ts"],"mappings":";KAAK,kBAAA;;;;;KAMO,gBAAA;EAIN,MAAA;EACA,WAAA,GAAc,kBAAA;AAAA;;;;;KAOR,8BAAA;EACV,SAAA,EAAW,gBAAA;EACX,YAAA;EACA,eAAA;AAAA;;;;;KAOU,yBAAA;;;AAAZ;;KA4BY,SAAA;;;AAAZ;;KAaY,wBAAA;EACN,IAAA;EAAgC,IAAA;EAAc,EAAA;AAAA;EAC9C,IAAA;EAAqC,EAAA;AAAA;EACrC,IAAA;EAA0B,KAAA;EAAe,EAAA;AAAA;EACzC,IAAA;EAA+B,EAAA;AAAA;EAC/B,IAAA;EAA2B,EAAA;AAAA;;;;AAMjC;KAAY,WAAA;EACV,IAAA;EACA,KAAA;EACA,GAAA;EACA,IAAA,EAAM,k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