@runtypelabs/persona 3.21.2 → 3.22.0

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.
Files changed (59) hide show
  1. package/README.md +67 -0
  2. package/dist/animations/glyph-cycle.d.cts +1 -1
  3. package/dist/animations/glyph-cycle.d.ts +1 -1
  4. package/dist/animations/{types-CWPIj66R.d.cts → types-BZVr1YOV.d.cts} +10 -0
  5. package/dist/animations/{types-CWPIj66R.d.ts → types-BZVr1YOV.d.ts} +10 -0
  6. package/dist/animations/wipe.d.cts +1 -1
  7. package/dist/animations/wipe.d.ts +1 -1
  8. package/dist/index.cjs +50 -43
  9. package/dist/index.cjs.map +1 -1
  10. package/dist/index.d.cts +474 -6
  11. package/dist/index.d.ts +474 -6
  12. package/dist/index.global.js +98 -88
  13. package/dist/index.global.js.map +1 -1
  14. package/dist/index.js +48 -41
  15. package/dist/index.js.map +1 -1
  16. package/dist/smart-dom-reader.cjs +1875 -0
  17. package/dist/smart-dom-reader.d.cts +4521 -0
  18. package/dist/smart-dom-reader.d.ts +4521 -0
  19. package/dist/smart-dom-reader.js +1848 -0
  20. package/dist/theme-editor.cjs +2282 -90
  21. package/dist/theme-editor.d.cts +348 -1
  22. package/dist/theme-editor.d.ts +348 -1
  23. package/dist/theme-editor.js +2267 -90
  24. package/package.json +9 -2
  25. package/src/client.test.ts +165 -0
  26. package/src/client.ts +144 -23
  27. package/src/components/composer-parts.test.ts +34 -0
  28. package/src/components/composer-parts.ts +9 -6
  29. package/src/index.ts +26 -0
  30. package/src/session.test.ts +258 -0
  31. package/src/session.ts +886 -30
  32. package/src/session.webmcp.test.ts +815 -0
  33. package/src/smart-dom-reader.test.ts +135 -0
  34. package/src/smart-dom-reader.ts +135 -0
  35. package/src/theme-editor/color-utils.test.ts +59 -0
  36. package/src/theme-editor/color-utils.ts +38 -2
  37. package/src/theme-editor/index.ts +35 -0
  38. package/src/theme-editor/webmcp/coerce.test.ts +86 -0
  39. package/src/theme-editor/webmcp/coerce.ts +286 -0
  40. package/src/theme-editor/webmcp/index.ts +45 -0
  41. package/src/theme-editor/webmcp/summary.ts +324 -0
  42. package/src/theme-editor/webmcp/tools.test.ts +205 -0
  43. package/src/theme-editor/webmcp/tools.ts +795 -0
  44. package/src/theme-editor/webmcp/types.ts +87 -0
  45. package/src/types.ts +186 -0
  46. package/src/ui.composer-keyboard.test.ts +229 -0
  47. package/src/ui.ts +127 -5
  48. package/src/utils/composer-history.test.ts +128 -0
  49. package/src/utils/composer-history.ts +113 -0
  50. package/src/utils/message-fingerprint.test.ts +20 -0
  51. package/src/utils/message-fingerprint.ts +2 -0
  52. package/src/utils/smart-dom-adapter.test.ts +257 -0
  53. package/src/utils/smart-dom-adapter.ts +217 -0
  54. package/{LICENSE → src/vendor/smart-dom-reader/LICENSE} +2 -2
  55. package/src/vendor/smart-dom-reader/README.md +61 -0
  56. package/src/vendor/smart-dom-reader/index.d.ts +476 -0
  57. package/src/vendor/smart-dom-reader/index.js +1618 -0
  58. package/src/webmcp-bridge.test.ts +429 -0
  59. package/src/webmcp-bridge.ts +547 -0
@@ -0,0 +1,476 @@
1
+ /**
2
+ * VENDORED type declarations — @mcp-b/smart-dom-reader v2.3.1 (MIT).
3
+ * Copied verbatim from upstream dist/index.d.mts (only the trailing sourceMappingURL
4
+ * comment removed). See ./index.js and ./README.md for why this is vendored.
5
+ */
6
+ /* eslint-disable */
7
+ //#region src/types.d.ts
8
+ type ExtractionMode = 'interactive' | 'full' | 'structure' | 'content';
9
+ interface ElementSelector {
10
+ css: string;
11
+ xpath: string;
12
+ textBased?: string;
13
+ dataTestId?: string;
14
+ ariaLabel?: string;
15
+ candidates?: ElementSelectorCandidate[];
16
+ }
17
+ interface ElementSelectorCandidate {
18
+ type: 'id' | 'data-testid' | 'role-aria' | 'name' | 'class-path' | 'css-path' | 'xpath' | 'text';
19
+ value: string;
20
+ score: number;
21
+ }
22
+ interface ElementContext {
23
+ nearestForm?: string;
24
+ nearestSection?: string;
25
+ nearestMain?: string;
26
+ nearestNav?: string;
27
+ parentChain: string[];
28
+ }
29
+ interface ElementInteraction {
30
+ click?: boolean;
31
+ change?: boolean;
32
+ submit?: boolean;
33
+ nav?: boolean;
34
+ disabled?: boolean;
35
+ hidden?: boolean;
36
+ role?: string;
37
+ form?: string;
38
+ }
39
+ interface ExtractedElement {
40
+ tag: string;
41
+ text: string;
42
+ selector: ElementSelector;
43
+ attributes: Record<string, string>;
44
+ context: ElementContext;
45
+ interaction: ElementInteraction;
46
+ children?: ExtractedElement[];
47
+ }
48
+ interface FormInfo {
49
+ selector: string;
50
+ action?: string;
51
+ method?: string;
52
+ inputs: ExtractedElement[];
53
+ buttons: ExtractedElement[];
54
+ }
55
+ interface PageLandmarks {
56
+ navigation: string[];
57
+ main: string[];
58
+ forms: string[];
59
+ headers: string[];
60
+ footers: string[];
61
+ articles: string[];
62
+ sections: string[];
63
+ }
64
+ interface PageState {
65
+ url: string;
66
+ title: string;
67
+ hasErrors: boolean;
68
+ isLoading: boolean;
69
+ hasModals: boolean;
70
+ hasFocus?: string;
71
+ }
72
+ interface SmartDOMResult {
73
+ mode: ExtractionMode;
74
+ timestamp: number;
75
+ page: PageState;
76
+ landmarks: PageLandmarks;
77
+ interactive: {
78
+ buttons: ExtractedElement[];
79
+ links: ExtractedElement[];
80
+ inputs: ExtractedElement[];
81
+ forms: FormInfo[];
82
+ clickable: ExtractedElement[];
83
+ };
84
+ semantic?: {
85
+ headings: ExtractedElement[];
86
+ images: ExtractedElement[];
87
+ tables: ExtractedElement[];
88
+ lists: ExtractedElement[];
89
+ articles: ExtractedElement[];
90
+ };
91
+ metadata?: {
92
+ totalElements: number;
93
+ extractedElements: number;
94
+ mainContent?: string;
95
+ language?: string;
96
+ };
97
+ }
98
+ interface FilterOptions {
99
+ includeSelectors?: string[];
100
+ excludeSelectors?: string[];
101
+ textContains?: string[];
102
+ textMatches?: RegExp[];
103
+ hasAttributes?: string[];
104
+ attributeValues?: Record<string, string | RegExp>;
105
+ tags?: string[];
106
+ interactionTypes?: Array<keyof ElementInteraction>;
107
+ withinSelectors?: string[];
108
+ nearText?: string;
109
+ }
110
+ interface ExtractionOptions {
111
+ mode: ExtractionMode;
112
+ maxDepth?: number;
113
+ includeHidden?: boolean;
114
+ includeShadowDOM?: boolean;
115
+ includeIframes?: boolean;
116
+ viewportOnly?: boolean;
117
+ mainContentOnly?: boolean;
118
+ customSelectors?: string[];
119
+ attributeTruncateLength?: number;
120
+ dataAttributeTruncateLength?: number;
121
+ textTruncateLength?: number;
122
+ filter?: FilterOptions;
123
+ }
124
+ interface RegionInfo {
125
+ selector: string;
126
+ label?: string;
127
+ role?: string;
128
+ interactiveCount: number;
129
+ hasForm?: boolean;
130
+ hasList?: boolean;
131
+ hasTable?: boolean;
132
+ hasMedia?: boolean;
133
+ buttonCount?: number;
134
+ linkCount?: number;
135
+ inputCount?: number;
136
+ textPreview?: string;
137
+ }
138
+ interface StructuralOverview {
139
+ regions: {
140
+ header?: RegionInfo;
141
+ navigation?: RegionInfo[];
142
+ main?: RegionInfo;
143
+ sidebar?: RegionInfo[];
144
+ footer?: RegionInfo;
145
+ modals?: RegionInfo[];
146
+ sections?: RegionInfo[];
147
+ };
148
+ forms: Array<{
149
+ selector: string;
150
+ location: string;
151
+ inputCount: number;
152
+ purpose?: string;
153
+ }>;
154
+ summary: {
155
+ totalInteractive: number;
156
+ totalForms: number;
157
+ totalSections: number;
158
+ hasModals: boolean;
159
+ hasErrors: boolean;
160
+ isLoading: boolean;
161
+ mainContentSelector?: string;
162
+ };
163
+ suggestions?: string[];
164
+ }
165
+ interface ContentExtractionOptions {
166
+ includeHeadings?: boolean;
167
+ includeLists?: boolean;
168
+ includeTables?: boolean;
169
+ includeMedia?: boolean;
170
+ preserveFormatting?: boolean;
171
+ maxTextLength?: number;
172
+ }
173
+ interface ExtractedContent {
174
+ selector: string;
175
+ text: {
176
+ headings?: Array<{
177
+ level: number;
178
+ text: string;
179
+ }>;
180
+ paragraphs?: string[];
181
+ lists?: Array<{
182
+ type: 'ul' | 'ol';
183
+ items: string[];
184
+ }>;
185
+ };
186
+ tables?: Array<{
187
+ headers: string[];
188
+ rows: string[][];
189
+ }>;
190
+ media?: Array<{
191
+ type: 'img' | 'video' | 'audio';
192
+ alt?: string;
193
+ src?: string;
194
+ }>;
195
+ metadata: {
196
+ wordCount: number;
197
+ hasInteractive: boolean;
198
+ };
199
+ }
200
+ //#endregion
201
+ //#region src/markdown-formatter.d.ts
202
+ type MarkdownDetailLevel = 'summary' | 'region' | 'deep';
203
+ interface MarkdownFormatOptions {
204
+ detail?: MarkdownDetailLevel;
205
+ maxTextLength?: number;
206
+ maxElements?: number;
207
+ }
208
+ type PageMeta = {
209
+ title?: string;
210
+ url?: string;
211
+ };
212
+ declare class MarkdownFormatter {
213
+ static structure(overview: StructuralOverview, _opts?: MarkdownFormatOptions, meta?: PageMeta): string;
214
+ static region(result: SmartDOMResult, opts?: MarkdownFormatOptions, meta?: PageMeta): string;
215
+ static content(content: ExtractedContent, opts?: MarkdownFormatOptions, meta?: PageMeta): string;
216
+ }
217
+ //#endregion
218
+ //#region src/bundle-types.d.ts
219
+ type ExtractionMethod = 'extractStructure' | 'extractRegion' | 'extractContent' | 'extractInteractive' | 'extractFull';
220
+ interface BaseExtractionArgs {
221
+ frameSelector?: string;
222
+ formatOptions?: MarkdownFormatOptions;
223
+ }
224
+ interface ExtractStructureArgs extends BaseExtractionArgs {
225
+ selector?: string;
226
+ }
227
+ interface ExtractRegionArgs extends BaseExtractionArgs {
228
+ selector: string;
229
+ mode?: 'interactive' | 'full';
230
+ options?: Partial<ExtractionOptions>;
231
+ }
232
+ interface ExtractContentArgs extends BaseExtractionArgs {
233
+ selector: string;
234
+ options?: ContentExtractionOptions;
235
+ }
236
+ interface ExtractInteractiveArgs extends BaseExtractionArgs {
237
+ selector?: string;
238
+ options?: Partial<ExtractionOptions>;
239
+ }
240
+ interface ExtractFullArgs extends BaseExtractionArgs {
241
+ selector?: string;
242
+ options?: Partial<ExtractionOptions>;
243
+ }
244
+ type ExtractionArgs = {
245
+ extractStructure: ExtractStructureArgs;
246
+ extractRegion: ExtractRegionArgs;
247
+ extractContent: ExtractContentArgs;
248
+ extractInteractive: ExtractInteractiveArgs;
249
+ extractFull: ExtractFullArgs;
250
+ };
251
+ interface ExtractionError {
252
+ error: string;
253
+ }
254
+ type ExtractionResult = string | ExtractionError;
255
+ interface SmartDOMReaderBundle {
256
+ executeExtraction<M extends ExtractionMethod>(method: M, args: ExtractionArgs[M]): ExtractionResult;
257
+ }
258
+ declare global {
259
+ interface Window {
260
+ SmartDOMReaderBundle: SmartDOMReaderBundle;
261
+ }
262
+ } //# sourceMappingURL=bundle-types.d.ts.map
263
+ //#endregion
264
+ //#region src/content-detection.d.ts
265
+ declare class ContentDetection {
266
+ /**
267
+ * Find the main content area of a page
268
+ * Inspired by dom-to-semantic-markdown's approach
269
+ */
270
+ static findMainContent(doc: Document): Element;
271
+ /**
272
+ * Detect main content using scoring algorithm
273
+ */
274
+ private static detectMainContent;
275
+ /**
276
+ * Collect content candidates
277
+ */
278
+ private static collectCandidates;
279
+ /**
280
+ * Calculate content score for an element
281
+ */
282
+ static calculateContentScore(element: Element): number;
283
+ /**
284
+ * Calculate link density in an element
285
+ */
286
+ private static calculateLinkDensity;
287
+ /**
288
+ * Check if an element is likely navigation
289
+ */
290
+ static isNavigation(element: Element): boolean;
291
+ /**
292
+ * Check if element is likely supplementary content
293
+ */
294
+ static isSupplementary(element: Element): boolean;
295
+ /**
296
+ * Detect page landmarks
297
+ */
298
+ static detectLandmarks(doc: Document): Record<string, Element[]>;
299
+ }
300
+ //#endregion
301
+ //#region src/progressive.d.ts
302
+ type SmartDomReaderCtor = new (options?: Partial<ExtractionOptions>) => SmartDOMReader;
303
+ declare class ProgressiveExtractor {
304
+ /**
305
+ * Step 1: Extract high-level structural overview
306
+ * This provides a "map" of the page for the AI to understand structure
307
+ */
308
+ static extractStructure(root: Document | Element): StructuralOverview;
309
+ /**
310
+ * Step 2: Extract detailed information from a specific region
311
+ */
312
+ static extractRegion(selector: string, doc: Document, options?: Partial<ExtractionOptions>, smartDomReaderCtor?: SmartDomReaderCtor): SmartDOMResult | null;
313
+ /**
314
+ * Step 3: Extract readable content from a region
315
+ */
316
+ static extractContent(selector: string, doc: Document, options?: ContentExtractionOptions): ExtractedContent | null;
317
+ /**
318
+ * Analyze a region and extract summary information
319
+ */
320
+ private static analyzeRegion;
321
+ /**
322
+ * Extract overview of forms on the page
323
+ */
324
+ private static extractFormOverview;
325
+ /**
326
+ * Calculate summary statistics
327
+ */
328
+ private static calculateSummary;
329
+ /**
330
+ * Generate AI-friendly suggestions
331
+ */
332
+ private static generateSuggestions;
333
+ /**
334
+ * Get text content with optional truncation
335
+ */
336
+ private static getTextContent;
337
+ }
338
+ //#endregion
339
+ //#region src/selectors.d.ts
340
+ declare class SelectorGenerator {
341
+ /**
342
+ * Generate multiple selector strategies for an element
343
+ */
344
+ static generateSelectors(element: Element): ElementSelector;
345
+ /**
346
+ * Generate a unique CSS selector for an element
347
+ */
348
+ private static generateCSSSelector;
349
+ /**
350
+ * Generate XPath for an element
351
+ */
352
+ private static generateXPath;
353
+ /**
354
+ * Generate a text-based selector for buttons and links
355
+ */
356
+ private static generateTextBasedSelector;
357
+ /**
358
+ * Get data-testid or similar attributes
359
+ */
360
+ private static getDataTestId;
361
+ /**
362
+ * Check if an ID is unique in the document
363
+ */
364
+ private static isUniqueId;
365
+ /**
366
+ * Check if a selector is unique within a container
367
+ */
368
+ private static isUniqueSelector;
369
+ private static isUniqueSelectorSafe;
370
+ /**
371
+ * Get meaningful classes (filtering out utility classes)
372
+ */
373
+ private static getMeaningfulClasses;
374
+ /**
375
+ * Optimize the selector path by removing unnecessary parts
376
+ */
377
+ private static optimizePath;
378
+ /**
379
+ * Get a human-readable path description
380
+ */
381
+ static getContextPath(element: Element): string[];
382
+ }
383
+ //#endregion
384
+ //#region src/index.d.ts
385
+ /**
386
+ * Smart DOM Reader - Full Extraction Approach
387
+ *
388
+ * This class provides complete DOM extraction in a single pass.
389
+ * Use this when you need all information upfront and have sufficient
390
+ * token budget for processing the complete output.
391
+ *
392
+ * Features:
393
+ * - Single-pass extraction of all elements
394
+ * - Two modes: 'interactive' (UI elements) or 'full' (includes content)
395
+ * - Efficient for automation and testing scenarios
396
+ * - Returns complete structured data immediately
397
+ */
398
+ declare class SmartDOMReader {
399
+ private options;
400
+ constructor(options?: Partial<ExtractionOptions>);
401
+ /**
402
+ * Main extraction method - extracts all data in one pass
403
+ * @param rootElement The document or element to extract from
404
+ * @param runtimeOptions Options to override constructor options
405
+ */
406
+ extract(rootElement?: Document | Element, runtimeOptions?: Partial<ExtractionOptions>): SmartDOMResult;
407
+ /**
408
+ * Extract page state information
409
+ */
410
+ private extractPageState;
411
+ /**
412
+ * Extract page landmarks
413
+ */
414
+ private extractLandmarks;
415
+ /**
416
+ * Convert elements to selector strings
417
+ */
418
+ private elementsToSelectors;
419
+ /**
420
+ * Extract interactive elements
421
+ */
422
+ private extractInteractiveElements;
423
+ /**
424
+ * Extract form information
425
+ */
426
+ private extractForms;
427
+ /**
428
+ * Extract semantic elements (full mode only)
429
+ */
430
+ private extractSemanticElements;
431
+ /**
432
+ * Extract metadata
433
+ */
434
+ private extractMetadata;
435
+ /**
436
+ * Check if element should be included based on options
437
+ */
438
+ private shouldIncludeElement;
439
+ /**
440
+ * Detect errors on the page
441
+ */
442
+ private detectErrors;
443
+ /**
444
+ * Detect if page is loading
445
+ */
446
+ private detectLoading;
447
+ /**
448
+ * Detect modal dialogs
449
+ */
450
+ private detectModals;
451
+ /**
452
+ * Get currently focused element
453
+ */
454
+ private getFocusedElement;
455
+ /**
456
+ * Quick extraction for interactive elements only
457
+ * @param doc The document to extract from
458
+ * @param options Extraction options
459
+ */
460
+ static extractInteractive(doc: Document, options?: Partial<ExtractionOptions>): SmartDOMResult;
461
+ /**
462
+ * Quick extraction for full content
463
+ * @param doc The document to extract from
464
+ * @param options Extraction options
465
+ */
466
+ static extractFull(doc: Document, options?: Partial<ExtractionOptions>): SmartDOMResult;
467
+ /**
468
+ * Extract from a specific element
469
+ * @param element The element to extract from
470
+ * @param mode The extraction mode
471
+ * @param options Additional options
472
+ */
473
+ static extractFromElement(element: Element, mode?: ExtractionMode, options?: Partial<ExtractionOptions>): SmartDOMResult;
474
+ }
475
+ //#endregion
476
+ export { ContentDetection, ContentExtractionOptions, ElementContext, ElementInteraction, ElementSelector, ElementSelectorCandidate, type ExtractContentArgs, type ExtractFullArgs, type ExtractInteractiveArgs, type ExtractRegionArgs, type ExtractStructureArgs, ExtractedContent, ExtractedElement, type ExtractionArgs, type ExtractionMethod, ExtractionMode, ExtractionOptions, type ExtractionResult, FilterOptions, FormInfo, type MarkdownFormatOptions, MarkdownFormatter, PageLandmarks, PageState, ProgressiveExtractor, RegionInfo, SelectorGenerator, SmartDOMReader, SmartDOMReader as default, SmartDOMResult, StructuralOverview };