@runtypelabs/persona 4.12.0 → 4.14.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 (68) hide show
  1. package/dist/codegen.cjs +1 -1
  2. package/dist/codegen.js +1 -1
  3. package/dist/context-mentions.d.cts +98 -6
  4. package/dist/context-mentions.d.ts +98 -6
  5. package/dist/index.cjs +64 -64
  6. package/dist/index.cjs.map +1 -1
  7. package/dist/index.d.cts +183 -8
  8. package/dist/index.d.ts +183 -8
  9. package/dist/index.global.js +54 -54
  10. package/dist/index.global.js.map +1 -1
  11. package/dist/index.js +67 -67
  12. package/dist/index.js.map +1 -1
  13. package/dist/launcher.global.js +1 -1
  14. package/dist/launcher.global.js.map +1 -1
  15. package/dist/smart-dom-reader.d.cts +98 -6
  16. package/dist/smart-dom-reader.d.ts +98 -6
  17. package/dist/theme-editor-preview.cjs +66 -66
  18. package/dist/theme-editor-preview.d.cts +100 -6
  19. package/dist/theme-editor-preview.d.ts +100 -6
  20. package/dist/theme-editor-preview.js +75 -75
  21. package/dist/theme-editor.cjs +10 -10
  22. package/dist/theme-editor.d.cts +134 -7
  23. package/dist/theme-editor.d.ts +134 -7
  24. package/dist/theme-editor.js +10 -10
  25. package/dist/theme-reference.cjs +1 -1
  26. package/dist/widget.css +1 -1
  27. package/package.json +1 -1
  28. package/src/artifacts-session.test.ts +106 -0
  29. package/src/client.test.ts +2 -2
  30. package/src/client.ts +4 -1
  31. package/src/components/artifact-card.ts +13 -2
  32. package/src/components/artifact-inline.ts +11 -2
  33. package/src/components/composer-builder.test.ts +2 -0
  34. package/src/components/composer-builder.ts +1 -1
  35. package/src/components/composer-parts.test.ts +2 -0
  36. package/src/components/composer-parts.ts +1 -1
  37. package/src/components/message-bubble.test.ts +7 -1
  38. package/src/components/message-bubble.ts +11 -8
  39. package/src/index-core.ts +34 -0
  40. package/src/session.ts +45 -4
  41. package/src/styles/widget.css +10 -1
  42. package/src/theme-editor/index.ts +5 -0
  43. package/src/theme-editor/presets.test.ts +43 -0
  44. package/src/theme-editor/presets.ts +101 -87
  45. package/src/theme-editor/sections.test.ts +39 -7
  46. package/src/theme-editor/sections.ts +60 -8
  47. package/src/theme-editor/state-preferences.test.ts +15 -0
  48. package/src/theme-editor/state.ts +46 -0
  49. package/src/theme-editor/types.ts +15 -1
  50. package/src/theme-editor/webmcp/tools.test.ts +13 -0
  51. package/src/theme-editor/webmcp/tools.ts +5 -0
  52. package/src/types.ts +139 -9
  53. package/src/ui.artifact-pane-gating.test.ts +5 -5
  54. package/src/ui.config-preferences.test.ts +166 -0
  55. package/src/ui.scroll-additive.test.ts +365 -0
  56. package/src/ui.scroll.test.ts +19 -6
  57. package/src/ui.ts +158 -53
  58. package/src/ui.typing-indicator.test.ts +135 -0
  59. package/src/utils/artifact-display.test.ts +180 -16
  60. package/src/utils/artifact-display.ts +155 -14
  61. package/src/utils/auto-follow.test.ts +38 -0
  62. package/src/utils/auto-follow.ts +35 -0
  63. package/src/utils/config-merge.test.ts +60 -0
  64. package/src/utils/config-merge.ts +6 -1
  65. package/src/utils/feature-preferences.test.ts +326 -0
  66. package/src/utils/feature-preferences.ts +498 -0
  67. package/src/utils/theme.test.ts +92 -0
  68. package/src/utils/tokens.ts +7 -7
@@ -1968,6 +1968,14 @@ type AgentToolsConfig = {
1968
1968
  };
1969
1969
  /** Artifact kinds for the Persona sidebar and dispatch payload */
1970
1970
  type PersonaArtifactKind = "markdown" | "component";
1971
+ type PersonaArtifactPresentation = {
1972
+ /**
1973
+ * Producer hint for where this artifact renders (content-disposition
1974
+ * model). Beats configured defaults; loses to explicit `files`/`byKind`
1975
+ * rules. Persona never infers it; the producer or host supplies it.
1976
+ */
1977
+ preferredMode?: PersonaArtifactDisplayModeInput;
1978
+ };
1971
1979
  /**
1972
1980
  * Agent configuration for agent execution mode.
1973
1981
  * When provided in the widget config, enables agent loop execution instead of flow dispatch.
@@ -2496,7 +2504,48 @@ type AgentWidgetArtifactsLayoutConfig = {
2496
2504
  jsonPayload: string;
2497
2505
  }) => void | Promise<void>;
2498
2506
  };
2499
- type PersonaArtifactDisplayMode = "card" | "panel" | "inline";
2507
+ /**
2508
+ * Where the artifact body renders by default. Every mode shows the compact
2509
+ * reference in the transcript; the mode names where the body goes:
2510
+ * nowhere yet (`collapsed`), the side panel (`panel`), or the conversation
2511
+ * itself (`inline`).
2512
+ */
2513
+ type PersonaArtifactDisplayMode = "collapsed" | "panel" | "inline";
2514
+ /**
2515
+ * Accepted wherever a display mode is written. `"card"` is a deprecated
2516
+ * alias of `"collapsed"` (the old name described the reference card, which
2517
+ * every mode shows, instead of where the body renders). Resolution and
2518
+ * parsing always canonicalize to `"collapsed"`.
2519
+ */
2520
+ type PersonaArtifactDisplayModeInput = PersonaArtifactDisplayMode | "card";
2521
+ /**
2522
+ * Display rules for file-backed artifacts. `byMediaType` keys are exact MIME
2523
+ * types (`"text/html"`) or major-type wildcards (`"image/*"`), matched
2524
+ * case-insensitively without parameters; exact beats wildcard.
2525
+ */
2526
+ type PersonaArtifactFilesDisplayRules = {
2527
+ default?: PersonaArtifactDisplayModeInput;
2528
+ byMediaType?: Record<string, PersonaArtifactDisplayModeInput>;
2529
+ };
2530
+ /**
2531
+ * Scoped artifact display rules. Matching resolves from the most specific
2532
+ * selector to `default`; see `resolveArtifactDisplay`.
2533
+ *
2534
+ * Across preference layers, one merge rule applies everywhere: a string value
2535
+ * replaces the whole subtree it names; an object refines it per key. So
2536
+ * `files: "inline"` overrides every lower-layer file rule, while
2537
+ * `files: { default: "inline" }` keeps lower-layer MIME exceptions.
2538
+ */
2539
+ type PersonaArtifactDisplayRules = {
2540
+ default?: PersonaArtifactDisplayModeInput;
2541
+ byKind?: Partial<Record<PersonaArtifactKind, PersonaArtifactDisplayModeInput>>;
2542
+ /**
2543
+ * @deprecated Use `byKind`. When both are present, `byKind` wins.
2544
+ */
2545
+ byType?: Partial<Record<PersonaArtifactKind, PersonaArtifactDisplayModeInput>>;
2546
+ /** Rules for any artifact carrying file metadata. */
2547
+ files?: PersonaArtifactDisplayModeInput | PersonaArtifactFilesDisplayRules;
2548
+ };
2500
2549
  /** Context handed to custom artifact actions. Content fields are best-effort: resolved from live session state or, after a refresh, from the persisted reference-card payload. */
2501
2550
  type PersonaArtifactActionContext = {
2502
2551
  artifactId: string | null;
@@ -2553,13 +2602,10 @@ type AgentWidgetArtifactsFeature = {
2553
2602
  allowedTypes?: PersonaArtifactKind[];
2554
2603
  /**
2555
2604
  * Where artifact bodies render. A single mode applies to all artifacts;
2556
- * the object form sets a default plus per-type overrides.
2605
+ * the object form sets a default plus scoped overrides.
2557
2606
  * Defaults to "panel" (current behavior).
2558
2607
  */
2559
- display?: PersonaArtifactDisplayMode | {
2560
- default?: PersonaArtifactDisplayMode;
2561
- byType?: Partial<Record<PersonaArtifactKind, PersonaArtifactDisplayMode>>;
2562
- };
2608
+ display?: PersonaArtifactDisplayModeInput | PersonaArtifactDisplayRules;
2563
2609
  /** Split / drawer dimensions and launcher widen behavior */
2564
2610
  layout?: AgentWidgetArtifactsLayoutConfig;
2565
2611
  /**
@@ -3288,6 +3334,46 @@ type AgentWidgetFeatureFlags = {
3288
3334
  */
3289
3335
  suggestReplies?: AgentWidgetSuggestRepliesFeature;
3290
3336
  };
3337
+ type WidgetPreferenceCapabilities = {
3338
+ artifacts?: boolean;
3339
+ tools?: boolean;
3340
+ reasoning?: boolean;
3341
+ };
3342
+ /**
3343
+ * Persistable artifact-layout choices. The full layout config deliberately is
3344
+ * not exposed because it also contains callbacks and embedder-owned chrome.
3345
+ */
3346
+ type WidgetArtifactLayoutPreference = Pick<AgentWidgetArtifactsLayoutConfig, "paneWidth" | "paneMaxWidth" | "paneMinWidth" | "expandLauncherPanelWhenOpen" | "expandedPanelWidth" | "resizable" | "resizableMinWidth" | "resizableMaxWidth">;
3347
+ /**
3348
+ * Curated, JSON-serializable display preferences in native `features` shape.
3349
+ *
3350
+ * Absence means inherit the next preference layer and ultimately Persona's
3351
+ * current default. Persist only explicit choices; resetting a choice deletes
3352
+ * its key.
3353
+ *
3354
+ * Capability facts (`artifacts.enabled`, `allowedTypes`), trusted iframe
3355
+ * security, callbacks, actions, renderers, labels, and theme styling are
3356
+ * intentionally excluded because they remain embedder/code-owned.
3357
+ */
3358
+ type WidgetPreferenceSlice = {
3359
+ showToolCalls?: boolean;
3360
+ showReasoning?: boolean;
3361
+ toolCallDisplay?: Pick<AgentWidgetToolCallDisplayFeature, "collapsedMode" | "expandable" | "grouped" | "groupedMode" | "loadingAnimation">;
3362
+ reasoningDisplay?: Pick<AgentWidgetReasoningDisplayFeature, "expandable" | "activePreview">;
3363
+ artifacts?: {
3364
+ /**
3365
+ * String and object forms are both persistable and mean different things
3366
+ * when layers merge: a string replaces every lower-layer display rule; an
3367
+ * object refines lower layers per selector key (same rule applies to
3368
+ * `display.files`).
3369
+ */
3370
+ display?: PersonaArtifactDisplayModeInput | PersonaArtifactDisplayRules;
3371
+ filePreview?: {
3372
+ enabled?: boolean;
3373
+ };
3374
+ layout?: WidgetArtifactLayoutPreference;
3375
+ };
3376
+ };
3291
3377
  /**
3292
3378
  * Feature config for the built-in `suggest_replies` quick-reply chips.
3293
3379
  * Chips render in the existing suggestions slot above the composer and are
@@ -5729,6 +5815,15 @@ type AgentWidgetConfig = {
5729
5815
  */
5730
5816
  colorScheme?: 'auto' | 'light' | 'dark';
5731
5817
  features?: AgentWidgetFeatureFlags;
5818
+ /**
5819
+ * Per-instance display overrides, applied over `features` through the
5820
+ * preference allowlist (security/capability keys cannot pass). String
5821
+ * `display` values replace the base rule subtree; objects refine it per
5822
+ * key. Each `controller.update({ preferences })` replaces the previous
5823
+ * slice wholesale (dropped keys revert to the base `features`); an
5824
+ * explicit-undefined patch clears it entirely.
5825
+ */
5826
+ preferences?: WidgetPreferenceSlice;
5732
5827
  /**
5733
5828
  * When true, focus the chat input after the panel opens and the open animation completes.
5734
5829
  * Applies to launcher mode (user click, controller.open(), autoExpand) and inline mode (on init).
@@ -6489,6 +6584,8 @@ type PersonaArtifactRecord = {
6489
6584
  props?: Record<string, unknown>;
6490
6585
  /** Present when this markdown artifact is a previewable file (see PersonaArtifactFileMeta). */
6491
6586
  file?: PersonaArtifactFileMeta;
6587
+ /** Optional presentation metadata such as the producer's display-mode hint. */
6588
+ presentation?: PersonaArtifactPresentation;
6492
6589
  };
6493
6590
 
6494
6591
  /** Field definition types for the declarative configurator system (headless: no DOM) */
@@ -6569,6 +6666,12 @@ interface FieldDef {
6569
6666
  formatValue?: (value: unknown) => unknown;
6570
6667
  /** Convert control input back into the stored value shape */
6571
6668
  parseValue?: (value: unknown) => unknown;
6669
+ /** Capability required for hosts to render this field. */
6670
+ requiresCapability?: keyof WidgetPreferenceCapabilities;
6671
+ /** The host may offer an inherit/reset action which deletes this path. */
6672
+ unsettable?: boolean;
6673
+ /** Label for the inherit/reset action. Default: "Use default". */
6674
+ unsetLabel?: string;
6572
6675
  }
6573
6676
  interface SectionDef {
6574
6677
  id: string;
@@ -6579,6 +6682,8 @@ interface SectionDef {
6579
6682
  collapsed?: boolean;
6580
6683
  /** Preset buttons for this section */
6581
6684
  presets?: SectionPreset[];
6685
+ /** Capability required for hosts to render this section. */
6686
+ requiresCapability?: keyof WidgetPreferenceCapabilities;
6582
6687
  }
6583
6688
  interface SectionPreset {
6584
6689
  id: string;
@@ -6609,6 +6714,8 @@ interface ThemeEditorPreset {
6609
6714
  toolCall?: AgentWidgetToolCallConfig;
6610
6715
  /** Tool call styling for dark mode (falls back to toolCall if not set) */
6611
6716
  darkToolCall?: AgentWidgetToolCallConfig;
6717
+ /** Sparse, persistable widget behavior layered separately from theme tokens. */
6718
+ behavior?: WidgetPreferenceSlice;
6612
6719
  preview: {
6613
6720
  primary: string;
6614
6721
  surface: string;
@@ -6659,6 +6766,8 @@ declare class ThemeEditorState {
6659
6766
  * - everything else → writes into AgentWidgetConfig
6660
6767
  */
6661
6768
  set(path: string, value: unknown): void;
6769
+ /** Delete a dot-path and prune empty parents so sparse preferences inherit. */
6770
+ unset(path: string): void;
6662
6771
  /** Batch-set multiple paths at once */
6663
6772
  setBatch(updates: Record<string, unknown>): void;
6664
6773
  /** Replace the entire theme */
@@ -6695,6 +6804,8 @@ declare const COMPONENT_SHAPE_SECTIONS: SectionDef[];
6695
6804
  /** Component color sections (can be scoped for light/dark) */
6696
6805
  declare const COMPONENT_COLOR_SECTIONS: SectionDef[];
6697
6806
  declare const COMPONENTS_SECTIONS: SectionDef[];
6807
+ declare const ARTIFACT_DISPLAY_PREFERENCE_SECTION: SectionDef;
6808
+ declare const STREAM_AND_ARTIFACTS_SUB_GROUP: SubGroupDef;
6698
6809
  declare const CONFIGURE_SUB_GROUPS: SubGroupDef[];
6699
6810
  declare const CONFIGURE_SECTIONS: SectionDef[];
6700
6811
  /** Section 1: Theme: color mode selection */
@@ -6812,6 +6923,22 @@ interface PreviewConfigOptions {
6812
6923
  declare function buildPreviewConfig(options: PreviewConfigOptions, shellModeOverride?: 'light' | 'dark'): AgentWidgetConfig;
6813
6924
  declare function buildPreviewConfigWithMessages(options: PreviewConfigOptions, messages: AgentWidgetMessage[], shellModeOverride?: 'light' | 'dark'): AgentWidgetConfig;
6814
6925
 
6926
+ /**
6927
+ * Imperative preview renderer for the theme editor.
6928
+ * Import from `@runtypelabs/persona/theme-editor/preview` (not the headless
6929
+ * `@runtypelabs/persona/theme-editor` subpath, which omits the widget runtime).
6930
+ *
6931
+ * Manages iframe-based widget previews with device frames, zoom, scenes, and compare mode.
6932
+ * No external DOM dependencies: only needs a container element to mount into.
6933
+ *
6934
+ * For advanced preview needs (background URLs, inline editing, contrast checking),
6935
+ * use the lifecycle hooks in `ThemePreviewOptions` and import shared building blocks
6936
+ * from `./preview-utils` directly.
6937
+ */
6938
+
6939
+ type PreviewShellMode = 'light' | 'dark';
6940
+ type CompareMode = 'off' | 'baseline' | 'themes';
6941
+
6815
6942
  /**
6816
6943
  * Interface Role → Token mapping layer.
6817
6944
  *
@@ -7104,4 +7231,4 @@ declare function runContrastChecks(state: ThemeEditorLike, level?: ContrastLevel
7104
7231
  /** Compact contrast warnings for the regions a mutation touched. */
7105
7232
  declare function quickContrastWarnings(state: ThemeEditorLike, pairKeys: string[], variant?: 'light' | 'dark' | 'both', level?: ContrastLevel): ContrastWarning[];
7106
7233
 
7107
- export { ADVANCED_TOKENS_SECTION, ALL_ROLES, ALL_TABS, BRAND_PALETTE_SECTION, BUILT_IN_PRESETS, type BuildTranscriptStreamFramesOptions, COLORS_SECTIONS, COLOR_FAMILIES, COMPONENTS_SECTIONS, COMPONENT_COLOR_SECTIONS, COMPONENT_SHAPE_SECTIONS, CONFIGURE_SECTIONS, CONFIGURE_SUB_GROUPS, CONTRAST_PAIRS, CSS_NAMED_COLORS, type ColorScaleOptions, type ConfigChangeListener, type ConfiguratorSnapshot, type ContrastCheck, type ContrastLevel, type ContrastReport, type ContrastWarning, type CreateThemeEditorToolsOptions, DEVICE_DIMENSIONS, type DetectedRoleAssignment, type EditTarget, type FieldDef, type FieldType, HOME_SUGGESTION_CHIPS, INTERFACE_ROLES_SECTION, MOCK_BROWSER_CONTENT, MOCK_WORKSPACE_CONTENT, type OnChangeCallback, PALETTE_SECTION, PREVIEW_STORAGE_ADAPTER, type PreviewConfigOptions, type PreviewScene, type PreviewShellPalette, type PreviewTranscriptEntryPreset, RADIUS_PRESETS, ROLE_ASSISTANT_MESSAGES, ROLE_BORDERS, ROLE_FAMILIES, ROLE_FAMILY_LABELS, ROLE_HEADER, ROLE_INPUT, ROLE_INTENSITIES, ROLE_LINKS_FOCUS, ROLE_PRIMARY_ACTIONS, ROLE_SCROLL_TO_BOTTOM, ROLE_SURFACES, ROLE_USER_MESSAGES, type RoleAssignmentOptions, type RoleFamily, type RoleIntensity, type RoleState, type RoleTarget, type RoleTargetKind, SEMANTIC_COLORS_SECTION, SHADE_KEYS, SHELL_STYLE_ID, STATUS_COLORS_SECTION, STATUS_PALETTE_SECTION, STYLE_SECTIONS, STYLE_SECTIONS_V2, type SectionDef, type SectionPreset, type SelectOption, type SliderOptions, type SubGroupDef, THEME_EDITOR_PRESETS, THEME_SECTION, type TabDef, type ThemeEditorLike, type ThemeEditorPreset, ThemeEditorState, type ThemeSummary, type TokenRefOptions, type ToolAnnotations, type ToolContent, type ToolExecute, type ToolImageContent, type ToolResult, type ToolTextContent, type TranscriptStreamFrame, type WebMcpTool, ZOOM_MAX, ZOOM_MIN, appendPreviewTranscriptEntry, applySceneConfig, applyShellTheme, buildPreviewConfig, buildPreviewConfigWithMessages, buildShellCss, buildSrcdoc, buildSummary, buildTranscriptStreamFrames, coerceColor, coerceFamily, coerceIntensity, coerceRadius, coerceRoundnessStyle, coerceScheme, convertFromPx, convertToPx, createPreviewMessages, createPreviewTranscriptEntry, createThemeEditorTools, detectRoleAssignment, escapeHtml, findSection, formatCssValue, generateColorScale, getPreviewTranscriptPresetLabel, getShellPalette, getThemeEditorPreset, hexToHsl, hslToHex, isValidHex, normalizeColorValue, paletteColorPath, parseCssValue, presetStreamsText, quickContrastWarnings, resolveRoleAssignment, resolveThemeColorPath, rgbToHex, runContrastChecks, scopeSection, tokenRefDisplayName, toolResult, wcagContrastRatio };
7234
+ export { ADVANCED_TOKENS_SECTION, ALL_ROLES, ALL_TABS, ARTIFACT_DISPLAY_PREFERENCE_SECTION, BRAND_PALETTE_SECTION, BUILT_IN_PRESETS, type BuildTranscriptStreamFramesOptions, COLORS_SECTIONS, COLOR_FAMILIES, COMPONENTS_SECTIONS, COMPONENT_COLOR_SECTIONS, COMPONENT_SHAPE_SECTIONS, CONFIGURE_SECTIONS, CONFIGURE_SUB_GROUPS, CONTRAST_PAIRS, CSS_NAMED_COLORS, type ColorScaleOptions, type CompareMode, type ConfigChangeListener, type ConfiguratorSnapshot, type ContrastCheck, type ContrastLevel, type ContrastReport, type ContrastWarning, type CreateThemeEditorToolsOptions, DEVICE_DIMENSIONS, type DetectedRoleAssignment, type EditTarget, type FieldDef, type FieldType, HOME_SUGGESTION_CHIPS, INTERFACE_ROLES_SECTION, MOCK_BROWSER_CONTENT, MOCK_WORKSPACE_CONTENT, type OnChangeCallback, PALETTE_SECTION, PREVIEW_STORAGE_ADAPTER, type PreviewConfigOptions, type PreviewScene, type PreviewShellMode, type PreviewShellPalette, type PreviewTranscriptEntryPreset, RADIUS_PRESETS, ROLE_ASSISTANT_MESSAGES, ROLE_BORDERS, ROLE_FAMILIES, ROLE_FAMILY_LABELS, ROLE_HEADER, ROLE_INPUT, ROLE_INTENSITIES, ROLE_LINKS_FOCUS, ROLE_PRIMARY_ACTIONS, ROLE_SCROLL_TO_BOTTOM, ROLE_SURFACES, ROLE_USER_MESSAGES, type RoleAssignmentOptions, type RoleFamily, type RoleIntensity, type RoleState, type RoleTarget, type RoleTargetKind, SEMANTIC_COLORS_SECTION, SHADE_KEYS, SHELL_STYLE_ID, STATUS_COLORS_SECTION, STATUS_PALETTE_SECTION, STREAM_AND_ARTIFACTS_SUB_GROUP, STYLE_SECTIONS, STYLE_SECTIONS_V2, type SectionDef, type SectionPreset, type SelectOption, type SliderOptions, type SubGroupDef, THEME_EDITOR_PRESETS, THEME_SECTION, type TabDef, type ThemeEditorLike, type ThemeEditorPreset, ThemeEditorState, type ThemeSummary, type TokenRefOptions, type ToolAnnotations, type ToolContent, type ToolExecute, type ToolImageContent, type ToolResult, type ToolTextContent, type TranscriptStreamFrame, type WebMcpTool, ZOOM_MAX, ZOOM_MIN, appendPreviewTranscriptEntry, applySceneConfig, applyShellTheme, buildPreviewConfig, buildPreviewConfigWithMessages, buildShellCss, buildSrcdoc, buildSummary, buildTranscriptStreamFrames, coerceColor, coerceFamily, coerceIntensity, coerceRadius, coerceRoundnessStyle, coerceScheme, convertFromPx, convertToPx, createPreviewMessages, createPreviewTranscriptEntry, createThemeEditorTools, detectRoleAssignment, escapeHtml, findSection, formatCssValue, generateColorScale, getPreviewTranscriptPresetLabel, getShellPalette, getThemeEditorPreset, hexToHsl, hslToHex, isValidHex, normalizeColorValue, paletteColorPath, parseCssValue, presetStreamsText, quickContrastWarnings, resolveRoleAssignment, resolveThemeColorPath, rgbToHex, runContrastChecks, scopeSection, tokenRefDisplayName, toolResult, wcagContrastRatio };
@@ -1968,6 +1968,14 @@ type AgentToolsConfig = {
1968
1968
  };
1969
1969
  /** Artifact kinds for the Persona sidebar and dispatch payload */
1970
1970
  type PersonaArtifactKind = "markdown" | "component";
1971
+ type PersonaArtifactPresentation = {
1972
+ /**
1973
+ * Producer hint for where this artifact renders (content-disposition
1974
+ * model). Beats configured defaults; loses to explicit `files`/`byKind`
1975
+ * rules. Persona never infers it; the producer or host supplies it.
1976
+ */
1977
+ preferredMode?: PersonaArtifactDisplayModeInput;
1978
+ };
1971
1979
  /**
1972
1980
  * Agent configuration for agent execution mode.
1973
1981
  * When provided in the widget config, enables agent loop execution instead of flow dispatch.
@@ -2496,7 +2504,48 @@ type AgentWidgetArtifactsLayoutConfig = {
2496
2504
  jsonPayload: string;
2497
2505
  }) => void | Promise<void>;
2498
2506
  };
2499
- type PersonaArtifactDisplayMode = "card" | "panel" | "inline";
2507
+ /**
2508
+ * Where the artifact body renders by default. Every mode shows the compact
2509
+ * reference in the transcript; the mode names where the body goes:
2510
+ * nowhere yet (`collapsed`), the side panel (`panel`), or the conversation
2511
+ * itself (`inline`).
2512
+ */
2513
+ type PersonaArtifactDisplayMode = "collapsed" | "panel" | "inline";
2514
+ /**
2515
+ * Accepted wherever a display mode is written. `"card"` is a deprecated
2516
+ * alias of `"collapsed"` (the old name described the reference card, which
2517
+ * every mode shows, instead of where the body renders). Resolution and
2518
+ * parsing always canonicalize to `"collapsed"`.
2519
+ */
2520
+ type PersonaArtifactDisplayModeInput = PersonaArtifactDisplayMode | "card";
2521
+ /**
2522
+ * Display rules for file-backed artifacts. `byMediaType` keys are exact MIME
2523
+ * types (`"text/html"`) or major-type wildcards (`"image/*"`), matched
2524
+ * case-insensitively without parameters; exact beats wildcard.
2525
+ */
2526
+ type PersonaArtifactFilesDisplayRules = {
2527
+ default?: PersonaArtifactDisplayModeInput;
2528
+ byMediaType?: Record<string, PersonaArtifactDisplayModeInput>;
2529
+ };
2530
+ /**
2531
+ * Scoped artifact display rules. Matching resolves from the most specific
2532
+ * selector to `default`; see `resolveArtifactDisplay`.
2533
+ *
2534
+ * Across preference layers, one merge rule applies everywhere: a string value
2535
+ * replaces the whole subtree it names; an object refines it per key. So
2536
+ * `files: "inline"` overrides every lower-layer file rule, while
2537
+ * `files: { default: "inline" }` keeps lower-layer MIME exceptions.
2538
+ */
2539
+ type PersonaArtifactDisplayRules = {
2540
+ default?: PersonaArtifactDisplayModeInput;
2541
+ byKind?: Partial<Record<PersonaArtifactKind, PersonaArtifactDisplayModeInput>>;
2542
+ /**
2543
+ * @deprecated Use `byKind`. When both are present, `byKind` wins.
2544
+ */
2545
+ byType?: Partial<Record<PersonaArtifactKind, PersonaArtifactDisplayModeInput>>;
2546
+ /** Rules for any artifact carrying file metadata. */
2547
+ files?: PersonaArtifactDisplayModeInput | PersonaArtifactFilesDisplayRules;
2548
+ };
2500
2549
  /** Context handed to custom artifact actions. Content fields are best-effort: resolved from live session state or, after a refresh, from the persisted reference-card payload. */
2501
2550
  type PersonaArtifactActionContext = {
2502
2551
  artifactId: string | null;
@@ -2553,13 +2602,10 @@ type AgentWidgetArtifactsFeature = {
2553
2602
  allowedTypes?: PersonaArtifactKind[];
2554
2603
  /**
2555
2604
  * Where artifact bodies render. A single mode applies to all artifacts;
2556
- * the object form sets a default plus per-type overrides.
2605
+ * the object form sets a default plus scoped overrides.
2557
2606
  * Defaults to "panel" (current behavior).
2558
2607
  */
2559
- display?: PersonaArtifactDisplayMode | {
2560
- default?: PersonaArtifactDisplayMode;
2561
- byType?: Partial<Record<PersonaArtifactKind, PersonaArtifactDisplayMode>>;
2562
- };
2608
+ display?: PersonaArtifactDisplayModeInput | PersonaArtifactDisplayRules;
2563
2609
  /** Split / drawer dimensions and launcher widen behavior */
2564
2610
  layout?: AgentWidgetArtifactsLayoutConfig;
2565
2611
  /**
@@ -3288,6 +3334,46 @@ type AgentWidgetFeatureFlags = {
3288
3334
  */
3289
3335
  suggestReplies?: AgentWidgetSuggestRepliesFeature;
3290
3336
  };
3337
+ type WidgetPreferenceCapabilities = {
3338
+ artifacts?: boolean;
3339
+ tools?: boolean;
3340
+ reasoning?: boolean;
3341
+ };
3342
+ /**
3343
+ * Persistable artifact-layout choices. The full layout config deliberately is
3344
+ * not exposed because it also contains callbacks and embedder-owned chrome.
3345
+ */
3346
+ type WidgetArtifactLayoutPreference = Pick<AgentWidgetArtifactsLayoutConfig, "paneWidth" | "paneMaxWidth" | "paneMinWidth" | "expandLauncherPanelWhenOpen" | "expandedPanelWidth" | "resizable" | "resizableMinWidth" | "resizableMaxWidth">;
3347
+ /**
3348
+ * Curated, JSON-serializable display preferences in native `features` shape.
3349
+ *
3350
+ * Absence means inherit the next preference layer and ultimately Persona's
3351
+ * current default. Persist only explicit choices; resetting a choice deletes
3352
+ * its key.
3353
+ *
3354
+ * Capability facts (`artifacts.enabled`, `allowedTypes`), trusted iframe
3355
+ * security, callbacks, actions, renderers, labels, and theme styling are
3356
+ * intentionally excluded because they remain embedder/code-owned.
3357
+ */
3358
+ type WidgetPreferenceSlice = {
3359
+ showToolCalls?: boolean;
3360
+ showReasoning?: boolean;
3361
+ toolCallDisplay?: Pick<AgentWidgetToolCallDisplayFeature, "collapsedMode" | "expandable" | "grouped" | "groupedMode" | "loadingAnimation">;
3362
+ reasoningDisplay?: Pick<AgentWidgetReasoningDisplayFeature, "expandable" | "activePreview">;
3363
+ artifacts?: {
3364
+ /**
3365
+ * String and object forms are both persistable and mean different things
3366
+ * when layers merge: a string replaces every lower-layer display rule; an
3367
+ * object refines lower layers per selector key (same rule applies to
3368
+ * `display.files`).
3369
+ */
3370
+ display?: PersonaArtifactDisplayModeInput | PersonaArtifactDisplayRules;
3371
+ filePreview?: {
3372
+ enabled?: boolean;
3373
+ };
3374
+ layout?: WidgetArtifactLayoutPreference;
3375
+ };
3376
+ };
3291
3377
  /**
3292
3378
  * Feature config for the built-in `suggest_replies` quick-reply chips.
3293
3379
  * Chips render in the existing suggestions slot above the composer and are
@@ -5729,6 +5815,15 @@ type AgentWidgetConfig = {
5729
5815
  */
5730
5816
  colorScheme?: 'auto' | 'light' | 'dark';
5731
5817
  features?: AgentWidgetFeatureFlags;
5818
+ /**
5819
+ * Per-instance display overrides, applied over `features` through the
5820
+ * preference allowlist (security/capability keys cannot pass). String
5821
+ * `display` values replace the base rule subtree; objects refine it per
5822
+ * key. Each `controller.update({ preferences })` replaces the previous
5823
+ * slice wholesale (dropped keys revert to the base `features`); an
5824
+ * explicit-undefined patch clears it entirely.
5825
+ */
5826
+ preferences?: WidgetPreferenceSlice;
5732
5827
  /**
5733
5828
  * When true, focus the chat input after the panel opens and the open animation completes.
5734
5829
  * Applies to launcher mode (user click, controller.open(), autoExpand) and inline mode (on init).
@@ -6489,6 +6584,8 @@ type PersonaArtifactRecord = {
6489
6584
  props?: Record<string, unknown>;
6490
6585
  /** Present when this markdown artifact is a previewable file (see PersonaArtifactFileMeta). */
6491
6586
  file?: PersonaArtifactFileMeta;
6587
+ /** Optional presentation metadata such as the producer's display-mode hint. */
6588
+ presentation?: PersonaArtifactPresentation;
6492
6589
  };
6493
6590
 
6494
6591
  /** Field definition types for the declarative configurator system (headless: no DOM) */
@@ -6569,6 +6666,12 @@ interface FieldDef {
6569
6666
  formatValue?: (value: unknown) => unknown;
6570
6667
  /** Convert control input back into the stored value shape */
6571
6668
  parseValue?: (value: unknown) => unknown;
6669
+ /** Capability required for hosts to render this field. */
6670
+ requiresCapability?: keyof WidgetPreferenceCapabilities;
6671
+ /** The host may offer an inherit/reset action which deletes this path. */
6672
+ unsettable?: boolean;
6673
+ /** Label for the inherit/reset action. Default: "Use default". */
6674
+ unsetLabel?: string;
6572
6675
  }
6573
6676
  interface SectionDef {
6574
6677
  id: string;
@@ -6579,6 +6682,8 @@ interface SectionDef {
6579
6682
  collapsed?: boolean;
6580
6683
  /** Preset buttons for this section */
6581
6684
  presets?: SectionPreset[];
6685
+ /** Capability required for hosts to render this section. */
6686
+ requiresCapability?: keyof WidgetPreferenceCapabilities;
6582
6687
  }
6583
6688
  interface SectionPreset {
6584
6689
  id: string;
@@ -6609,6 +6714,8 @@ interface ThemeEditorPreset {
6609
6714
  toolCall?: AgentWidgetToolCallConfig;
6610
6715
  /** Tool call styling for dark mode (falls back to toolCall if not set) */
6611
6716
  darkToolCall?: AgentWidgetToolCallConfig;
6717
+ /** Sparse, persistable widget behavior layered separately from theme tokens. */
6718
+ behavior?: WidgetPreferenceSlice;
6612
6719
  preview: {
6613
6720
  primary: string;
6614
6721
  surface: string;
@@ -6659,6 +6766,8 @@ declare class ThemeEditorState {
6659
6766
  * - everything else → writes into AgentWidgetConfig
6660
6767
  */
6661
6768
  set(path: string, value: unknown): void;
6769
+ /** Delete a dot-path and prune empty parents so sparse preferences inherit. */
6770
+ unset(path: string): void;
6662
6771
  /** Batch-set multiple paths at once */
6663
6772
  setBatch(updates: Record<string, unknown>): void;
6664
6773
  /** Replace the entire theme */
@@ -6695,6 +6804,8 @@ declare const COMPONENT_SHAPE_SECTIONS: SectionDef[];
6695
6804
  /** Component color sections (can be scoped for light/dark) */
6696
6805
  declare const COMPONENT_COLOR_SECTIONS: SectionDef[];
6697
6806
  declare const COMPONENTS_SECTIONS: SectionDef[];
6807
+ declare const ARTIFACT_DISPLAY_PREFERENCE_SECTION: SectionDef;
6808
+ declare const STREAM_AND_ARTIFACTS_SUB_GROUP: SubGroupDef;
6698
6809
  declare const CONFIGURE_SUB_GROUPS: SubGroupDef[];
6699
6810
  declare const CONFIGURE_SECTIONS: SectionDef[];
6700
6811
  /** Section 1: Theme: color mode selection */
@@ -6812,6 +6923,22 @@ interface PreviewConfigOptions {
6812
6923
  declare function buildPreviewConfig(options: PreviewConfigOptions, shellModeOverride?: 'light' | 'dark'): AgentWidgetConfig;
6813
6924
  declare function buildPreviewConfigWithMessages(options: PreviewConfigOptions, messages: AgentWidgetMessage[], shellModeOverride?: 'light' | 'dark'): AgentWidgetConfig;
6814
6925
 
6926
+ /**
6927
+ * Imperative preview renderer for the theme editor.
6928
+ * Import from `@runtypelabs/persona/theme-editor/preview` (not the headless
6929
+ * `@runtypelabs/persona/theme-editor` subpath, which omits the widget runtime).
6930
+ *
6931
+ * Manages iframe-based widget previews with device frames, zoom, scenes, and compare mode.
6932
+ * No external DOM dependencies: only needs a container element to mount into.
6933
+ *
6934
+ * For advanced preview needs (background URLs, inline editing, contrast checking),
6935
+ * use the lifecycle hooks in `ThemePreviewOptions` and import shared building blocks
6936
+ * from `./preview-utils` directly.
6937
+ */
6938
+
6939
+ type PreviewShellMode = 'light' | 'dark';
6940
+ type CompareMode = 'off' | 'baseline' | 'themes';
6941
+
6815
6942
  /**
6816
6943
  * Interface Role → Token mapping layer.
6817
6944
  *
@@ -7104,4 +7231,4 @@ declare function runContrastChecks(state: ThemeEditorLike, level?: ContrastLevel
7104
7231
  /** Compact contrast warnings for the regions a mutation touched. */
7105
7232
  declare function quickContrastWarnings(state: ThemeEditorLike, pairKeys: string[], variant?: 'light' | 'dark' | 'both', level?: ContrastLevel): ContrastWarning[];
7106
7233
 
7107
- export { ADVANCED_TOKENS_SECTION, ALL_ROLES, ALL_TABS, BRAND_PALETTE_SECTION, BUILT_IN_PRESETS, type BuildTranscriptStreamFramesOptions, COLORS_SECTIONS, COLOR_FAMILIES, COMPONENTS_SECTIONS, COMPONENT_COLOR_SECTIONS, COMPONENT_SHAPE_SECTIONS, CONFIGURE_SECTIONS, CONFIGURE_SUB_GROUPS, CONTRAST_PAIRS, CSS_NAMED_COLORS, type ColorScaleOptions, type ConfigChangeListener, type ConfiguratorSnapshot, type ContrastCheck, type ContrastLevel, type ContrastReport, type ContrastWarning, type CreateThemeEditorToolsOptions, DEVICE_DIMENSIONS, type DetectedRoleAssignment, type EditTarget, type FieldDef, type FieldType, HOME_SUGGESTION_CHIPS, INTERFACE_ROLES_SECTION, MOCK_BROWSER_CONTENT, MOCK_WORKSPACE_CONTENT, type OnChangeCallback, PALETTE_SECTION, PREVIEW_STORAGE_ADAPTER, type PreviewConfigOptions, type PreviewScene, type PreviewShellPalette, type PreviewTranscriptEntryPreset, RADIUS_PRESETS, ROLE_ASSISTANT_MESSAGES, ROLE_BORDERS, ROLE_FAMILIES, ROLE_FAMILY_LABELS, ROLE_HEADER, ROLE_INPUT, ROLE_INTENSITIES, ROLE_LINKS_FOCUS, ROLE_PRIMARY_ACTIONS, ROLE_SCROLL_TO_BOTTOM, ROLE_SURFACES, ROLE_USER_MESSAGES, type RoleAssignmentOptions, type RoleFamily, type RoleIntensity, type RoleState, type RoleTarget, type RoleTargetKind, SEMANTIC_COLORS_SECTION, SHADE_KEYS, SHELL_STYLE_ID, STATUS_COLORS_SECTION, STATUS_PALETTE_SECTION, STYLE_SECTIONS, STYLE_SECTIONS_V2, type SectionDef, type SectionPreset, type SelectOption, type SliderOptions, type SubGroupDef, THEME_EDITOR_PRESETS, THEME_SECTION, type TabDef, type ThemeEditorLike, type ThemeEditorPreset, ThemeEditorState, type ThemeSummary, type TokenRefOptions, type ToolAnnotations, type ToolContent, type ToolExecute, type ToolImageContent, type ToolResult, type ToolTextContent, type TranscriptStreamFrame, type WebMcpTool, ZOOM_MAX, ZOOM_MIN, appendPreviewTranscriptEntry, applySceneConfig, applyShellTheme, buildPreviewConfig, buildPreviewConfigWithMessages, buildShellCss, buildSrcdoc, buildSummary, buildTranscriptStreamFrames, coerceColor, coerceFamily, coerceIntensity, coerceRadius, coerceRoundnessStyle, coerceScheme, convertFromPx, convertToPx, createPreviewMessages, createPreviewTranscriptEntry, createThemeEditorTools, detectRoleAssignment, escapeHtml, findSection, formatCssValue, generateColorScale, getPreviewTranscriptPresetLabel, getShellPalette, getThemeEditorPreset, hexToHsl, hslToHex, isValidHex, normalizeColorValue, paletteColorPath, parseCssValue, presetStreamsText, quickContrastWarnings, resolveRoleAssignment, resolveThemeColorPath, rgbToHex, runContrastChecks, scopeSection, tokenRefDisplayName, toolResult, wcagContrastRatio };
7234
+ export { ADVANCED_TOKENS_SECTION, ALL_ROLES, ALL_TABS, ARTIFACT_DISPLAY_PREFERENCE_SECTION, BRAND_PALETTE_SECTION, BUILT_IN_PRESETS, type BuildTranscriptStreamFramesOptions, COLORS_SECTIONS, COLOR_FAMILIES, COMPONENTS_SECTIONS, COMPONENT_COLOR_SECTIONS, COMPONENT_SHAPE_SECTIONS, CONFIGURE_SECTIONS, CONFIGURE_SUB_GROUPS, CONTRAST_PAIRS, CSS_NAMED_COLORS, type ColorScaleOptions, type CompareMode, type ConfigChangeListener, type ConfiguratorSnapshot, type ContrastCheck, type ContrastLevel, type ContrastReport, type ContrastWarning, type CreateThemeEditorToolsOptions, DEVICE_DIMENSIONS, type DetectedRoleAssignment, type EditTarget, type FieldDef, type FieldType, HOME_SUGGESTION_CHIPS, INTERFACE_ROLES_SECTION, MOCK_BROWSER_CONTENT, MOCK_WORKSPACE_CONTENT, type OnChangeCallback, PALETTE_SECTION, PREVIEW_STORAGE_ADAPTER, type PreviewConfigOptions, type PreviewScene, type PreviewShellMode, type PreviewShellPalette, type PreviewTranscriptEntryPreset, RADIUS_PRESETS, ROLE_ASSISTANT_MESSAGES, ROLE_BORDERS, ROLE_FAMILIES, ROLE_FAMILY_LABELS, ROLE_HEADER, ROLE_INPUT, ROLE_INTENSITIES, ROLE_LINKS_FOCUS, ROLE_PRIMARY_ACTIONS, ROLE_SCROLL_TO_BOTTOM, ROLE_SURFACES, ROLE_USER_MESSAGES, type RoleAssignmentOptions, type RoleFamily, type RoleIntensity, type RoleState, type RoleTarget, type RoleTargetKind, SEMANTIC_COLORS_SECTION, SHADE_KEYS, SHELL_STYLE_ID, STATUS_COLORS_SECTION, STATUS_PALETTE_SECTION, STREAM_AND_ARTIFACTS_SUB_GROUP, STYLE_SECTIONS, STYLE_SECTIONS_V2, type SectionDef, type SectionPreset, type SelectOption, type SliderOptions, type SubGroupDef, THEME_EDITOR_PRESETS, THEME_SECTION, type TabDef, type ThemeEditorLike, type ThemeEditorPreset, ThemeEditorState, type ThemeSummary, type TokenRefOptions, type ToolAnnotations, type ToolContent, type ToolExecute, type ToolImageContent, type ToolResult, type ToolTextContent, type TranscriptStreamFrame, type WebMcpTool, ZOOM_MAX, ZOOM_MIN, appendPreviewTranscriptEntry, applySceneConfig, applyShellTheme, buildPreviewConfig, buildPreviewConfigWithMessages, buildShellCss, buildSrcdoc, buildSummary, buildTranscriptStreamFrames, coerceColor, coerceFamily, coerceIntensity, coerceRadius, coerceRoundnessStyle, coerceScheme, convertFromPx, convertToPx, createPreviewMessages, createPreviewTranscriptEntry, createThemeEditorTools, detectRoleAssignment, escapeHtml, findSection, formatCssValue, generateColorScale, getPreviewTranscriptPresetLabel, getShellPalette, getThemeEditorPreset, hexToHsl, hslToHex, isValidHex, normalizeColorValue, paletteColorPath, parseCssValue, presetStreamsText, quickContrastWarnings, resolveRoleAssignment, resolveThemeColorPath, rgbToHex, runContrastChecks, scopeSection, tokenRefDisplayName, toolResult, wcagContrastRatio };