@runtypelabs/persona 3.19.0 → 3.21.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.
package/dist/index.d.cts CHANGED
@@ -757,10 +757,28 @@ type FileContentPart = {
757
757
  mimeType: string;
758
758
  filename: string;
759
759
  };
760
+ /**
761
+ * Audio content part for multi-modal messages
762
+ * Supports base64 data URIs or URLs
763
+ */
764
+ type AudioContentPart = {
765
+ type: 'audio';
766
+ audio: string;
767
+ mimeType?: string;
768
+ };
769
+ /**
770
+ * Video content part for multi-modal messages
771
+ * Supports base64 data URIs or URLs
772
+ */
773
+ type VideoContentPart = {
774
+ type: 'video';
775
+ video: string;
776
+ mimeType?: string;
777
+ };
760
778
  /**
761
779
  * Union type for all content part types
762
780
  */
763
- type ContentPart = TextContentPart | ImageContentPart | FileContentPart;
781
+ type ContentPart = TextContentPart | ImageContentPart | FileContentPart | AudioContentPart | VideoContentPart;
764
782
  /**
765
783
  * Message content can be a simple string or an array of content parts
766
784
  */
@@ -4266,6 +4284,22 @@ type InjectMessageOptions = {
4266
4284
  * Consumers can detect this in `messageTransform` to render custom UI.
4267
4285
  */
4268
4286
  voiceProcessing?: boolean;
4287
+ /**
4288
+ * Raw structured payload (typically a JSON string) representing the
4289
+ * full directive that produced this message — e.g. `{ "text": "...",
4290
+ * "component": "Foo", "props": {...} }`.
4291
+ *
4292
+ * Mirrors the field populated by stream parsers during normal LLM
4293
+ * responses. Set this when injecting a message that should render as a
4294
+ * component directive (`hasComponentDirective` /
4295
+ * `extractComponentDirectiveFromMessage` look at `rawContent` first).
4296
+ *
4297
+ * Priority for the API payload remains:
4298
+ * `contentParts > llmContent > rawContent > content`. Pass `llmContent`
4299
+ * alongside `rawContent` if the LLM should see something other than the
4300
+ * raw directive.
4301
+ */
4302
+ rawContent?: string;
4269
4303
  };
4270
4304
  /**
4271
4305
  * Options for injecting assistant messages (most common case).
@@ -4282,6 +4316,57 @@ type InjectUserMessageOptions = Omit<InjectMessageOptions, "role">;
4282
4316
  * Role defaults to 'system'.
4283
4317
  */
4284
4318
  type InjectSystemMessageOptions = Omit<InjectMessageOptions, "role">;
4319
+ /**
4320
+ * Options for injecting an assistant message that renders as a component
4321
+ * directive — sugar over `injectAssistantMessage` for the common case of
4322
+ * "render this registered component, same as if the LLM had emitted it".
4323
+ *
4324
+ * Equivalent to calling `injectAssistantMessage({ content: text, rawContent:
4325
+ * JSON.stringify({ text, component, props }), llmContent })`.
4326
+ *
4327
+ * @example
4328
+ * widget.injectComponentDirective({
4329
+ * component: "DynamicForm",
4330
+ * props: { title: "Book a demo", fields: [...] },
4331
+ * text: "Share your details to book a demo.",
4332
+ * llmContent: "[Showed booking form]"
4333
+ * });
4334
+ */
4335
+ type InjectComponentDirectiveOptions = {
4336
+ /**
4337
+ * Name of a renderer registered via `componentRegistry.register(...)`.
4338
+ */
4339
+ component: string;
4340
+ /**
4341
+ * Props passed to the component renderer.
4342
+ */
4343
+ props?: Record<string, unknown>;
4344
+ /**
4345
+ * Bubble copy displayed above (or with) the rendered component.
4346
+ * Mirrors the `text` field in a streamed JSON directive.
4347
+ * @default ""
4348
+ */
4349
+ text?: string;
4350
+ /**
4351
+ * Content sent to the LLM in API requests. When omitted, the raw
4352
+ * directive JSON is what the LLM would see (per the standard
4353
+ * priority chain). Provide a redacted/short version to avoid sending
4354
+ * the full directive in subsequent turns.
4355
+ */
4356
+ llmContent?: string;
4357
+ /**
4358
+ * Optional message ID. If omitted, an assistant id is auto-generated.
4359
+ */
4360
+ id?: string;
4361
+ /**
4362
+ * Optional creation timestamp (ISO string). If omitted, uses current time.
4363
+ */
4364
+ createdAt?: string;
4365
+ /**
4366
+ * Optional sequence number for ordering.
4367
+ */
4368
+ sequence?: number;
4369
+ };
4285
4370
  type PersonaArtifactRecord = {
4286
4371
  id: string;
4287
4372
  artifactType: PersonaArtifactKind;
@@ -4738,6 +4823,24 @@ declare class AgentWidgetSession {
4738
4823
  * Inject multiple messages in a single batch with one sort and one render pass.
4739
4824
  */
4740
4825
  injectMessageBatch(optionsList: InjectMessageOptions[]): AgentWidgetMessage[];
4826
+ /**
4827
+ * Convenience method for injecting a registered component directive as
4828
+ * an assistant message — the same shape Persona produces from a streamed
4829
+ * `{ "text": "...", "component": "...", "props": {...} }` payload.
4830
+ *
4831
+ * Sets `content` to `text`, `rawContent` to the JSON directive (so
4832
+ * `extractComponentDirectiveFromMessage` can find it), and forwards
4833
+ * `llmContent` / `id` / `createdAt` / `sequence`.
4834
+ *
4835
+ * @example
4836
+ * session.injectComponentDirective({
4837
+ * component: "DynamicForm",
4838
+ * props: { title: "Book a demo", fields: [...] },
4839
+ * text: "Share your details to book a demo.",
4840
+ * llmContent: "[Showed booking form]"
4841
+ * });
4842
+ */
4843
+ injectComponentDirective(options: InjectComponentDirectiveOptions): AgentWidgetMessage;
4741
4844
  sendMessage(rawInput: string, options?: {
4742
4845
  viaVoice?: boolean;
4743
4846
  /** Multi-modal content parts (e.g., images) to include with the message */
@@ -4931,6 +5034,12 @@ type Controller = {
4931
5034
  * Inject multiple messages in a single batch with one sort and one render pass.
4932
5035
  */
4933
5036
  injectMessageBatch: (optionsList: InjectMessageOptions[]) => AgentWidgetMessage[];
5037
+ /**
5038
+ * Convenience method for injecting an assistant message that renders as a
5039
+ * registered component — same shape Persona produces from a streamed
5040
+ * `{ "text": "...", "component": "...", "props": {...} }` payload.
5041
+ */
5042
+ injectComponentDirective: (options: InjectComponentDirectiveOptions) => AgentWidgetMessage;
4934
5043
  /**
4935
5044
  * @deprecated Use injectMessage() instead.
4936
5045
  */
@@ -6504,11 +6613,20 @@ declare function createComponentMiddleware(): {
6504
6613
  reset: () => void;
6505
6614
  };
6506
6615
  /**
6507
- * Checks if a message contains a component directive in its raw content
6616
+ * Checks if a message contains a component directive.
6617
+ *
6618
+ * Looks at `rawContent` first (the field set by stream parsers); falls back
6619
+ * to `content` when it looks like JSON, so injected messages that pass the
6620
+ * directive via `content` (or have no `rawContent`) are still recognized.
6508
6621
  */
6509
6622
  declare function hasComponentDirective(message: AgentWidgetMessage): boolean;
6510
6623
  /**
6511
- * Extracts component directive from a complete message
6624
+ * Extracts component directive from a complete message.
6625
+ *
6626
+ * Looks at `rawContent` first (the field set by stream parsers); falls back
6627
+ * to `content` when it looks like JSON, so injected messages that pass the
6628
+ * directive via `content` (or have no `rawContent`) render the same as
6629
+ * streamed ones.
6512
6630
  */
6513
6631
  declare function extractComponentDirectiveFromMessage(message: AgentWidgetMessage): ComponentDirective | null;
6514
6632
 
@@ -6660,4 +6778,4 @@ declare function createVoiceProvider(config: VoiceConfig): VoiceProvider;
6660
6778
  declare function createBestAvailableVoiceProvider(config?: Partial<VoiceConfig>): VoiceProvider;
6661
6779
  declare function isVoiceSupported(config?: Partial<VoiceConfig>): boolean;
6662
6780
 
6663
- export { ASK_USER_QUESTION_TOOL_NAME, type AgentConfig, type AgentExecutionState, type AgentLoopConfig, type AgentMessageMetadata, type AgentRequestOptions, type AgentToolsConfig, type AgentWidgetAgentRequestPayload, type AgentWidgetApproval, type AgentWidgetApprovalConfig, type AgentWidgetArtifactsFeature, type AgentWidgetArtifactsLayoutConfig, type AgentWidgetAskUserQuestionFeature, type AgentWidgetAskUserQuestionStyles, type AgentWidgetAttachmentsConfig, type AgentWidgetAvatarConfig, AgentWidgetClient, type AgentWidgetComposerConfig, type AgentWidgetConfig, type AgentWidgetController, type AgentWidgetControllerEventMap, type AgentWidgetCustomFetch, type AgentWidgetDockConfig, type AgentWidgetEvent, type AgentWidgetFeatureFlags, type AgentWidgetHeaderLayoutConfig, type AgentWidgetHeadersFunction, type AgentWidgetInitHandle, type AgentWidgetInitOptions, type AgentWidgetLauncherConfig, type AgentWidgetLayoutConfig, type AgentWidgetLoadingIndicatorConfig, type AgentWidgetMarkdownConfig, type AgentWidgetMarkdownOptions, type AgentWidgetMarkdownRendererOverrides, type AgentWidgetMessage, type AgentWidgetMessageActionsConfig, type AgentWidgetMessageFeedback, type AgentWidgetMessageLayoutConfig, type AgentWidgetPlugin, type AgentWidgetRequestPayload, type AgentWidgetSSEEventParser, type AgentWidgetSSEEventResult, AgentWidgetSession, type AgentWidgetSessionStatus, type AgentWidgetStreamAnimationBuffer, type AgentWidgetStreamAnimationBuiltinType, type AgentWidgetStreamAnimationFeature, type AgentWidgetStreamAnimationPlaceholder, type AgentWidgetStreamAnimationType, type AgentWidgetStreamParser, type AgentWidgetStreamParserResult, type AgentWidgetTimestampConfig, type ArtifactConfigPayload, type ArtifactPaneTokens, type ArtifactTabTokens, type ArtifactToolbarTokens, type AskUserQuestionOption, type AskUserQuestionPayload, type AskUserQuestionPrompt, AttachmentManager, type AttachmentManagerConfig, type BorderScale, type CSATFeedbackOptions, type ClientChatRequest, type ClientFeedbackRequest, type ClientFeedbackType, type ClientInitResponse, type ClientSession, type CodeFormat, type CodeGeneratorHooks, type CodeGeneratorOptions, type ColorPalette, type ColorShade, type ComboButtonHandle, type ComponentContext, type ComponentDirective, type ComponentRenderer, type ComponentTokens, type ComposerBuildContext, type ComposerElements, type ContentPart, type CreateComboButtonOptions, type CreateDropdownOptions, type CreateIconButtonOptions, type CreateLabelButtonOptions, type CreateStandardBubbleOptions, type CreateThemeOptions, type CreateToggleGroupOptions, DEFAULT_COMPONENTS, DEFAULT_FLOATING_LAUNCHER_MAX_WIDTH, DEFAULT_FLOATING_LAUNCHER_WIDTH, DEFAULT_PALETTE, DEFAULT_SEMANTIC, DEFAULT_WIDGET_CONFIG, type DeepPartial, type DemoCarouselHandle, type DemoCarouselItem, type DemoCarouselOptions, type DomContextMode, type DomContextOptions, type DropdownMenuHandle, type DropdownMenuItem, type EnrichedPageElement, type EventStreamBadgeColor, type EventStreamConfig, type EventStreamPayloadRenderContext, type EventStreamRowRenderContext, type EventStreamToolbarRenderContext, type EventStreamViewRenderContext, type FormatEnrichedContextOptions, type HeaderBuildContext, type HeaderElements, type HeaderLayoutContext, type HeaderLayoutRenderer, type HeaderRenderContext, type IconButtonTokens, type IconName, type IdleIndicatorRenderContext, type ImageContentPart, type InjectAssistantMessageOptions, type InjectMessageOptions, type InjectSystemMessageOptions, type InjectUserMessageOptions, type LabelButtonTokens, type LoadingIndicatorRenderContext, type LoadingIndicatorRenderer, type MarkdownProcessorOptions, type MessageActionCallbacks, type MessageContent, type MessageRenderContext, type MessageTransform, type NPSFeedbackOptions, PRESETS, PRESET_FULLSCREEN, PRESET_MINIMAL, PRESET_SHOP, type ParseOptionsConfig, type ParseRule, type PendingAttachment, type PersonaArtifactKind, type PersonaArtifactManualUpsert, type PersonaArtifactRecord, type PersonaTheme, type PersonaThemePlugin, type RadiusScale, type RuleScoringContext, type SSEEventCallback, type SSEEventRecord, type SanitizeFunction, type SemanticColors, type SemanticSpacing, type SemanticTypography, type ShadowScale, type SlotRenderContext, type SlotRenderer, type SpacingScale, type StreamAnimationContext, type StreamAnimationPlugin, THEME_ZONES, type TextContentPart, type ThemeValidationError, type ThemeValidationResult, type ThemeZone, type ToggleGroupHandle, type ToggleGroupItem, type ToggleGroupTokens, type TokenReference, type TypographyScale, VERSION, type VoiceConfig, type VoiceProvider, type VoiceResult, type VoiceStatus, type WidgetHostLayout, type WidgetHostLayoutMode, type WidgetLayoutSlot, type WidgetPreset, accessibilityPlugin, animationsPlugin, applyThemeVariables, attachHeaderToContainer, brandPlugin, buildComposer, buildDefaultHeader, buildHeader, buildHeaderWithLayout, buildMinimalHeader, collectEnrichedPageContext, componentRegistry, createActionManager, createAgentExperience, createAskUserQuestionBubble, createBestAvailableVoiceProvider, createBubbleWithLayout, createCSATFeedback, createComboButton, createComponentMiddleware, createComponentStreamParser, createDefaultSanitizer, createDemoCarousel, createDirectivePostprocessor, createDropdownMenu, createFlexibleJsonStreamParser, createIconButton, createImagePart, createJsonStreamParser, createLabelButton, createLocalStorageAdapter, createMarkdownProcessor, createMarkdownProcessorFromConfig, createMessageActions, createNPSFeedback, createPlainTextParser, createPlugin, createRegexJsonParser, createStandardBubble, createTextPart, createTheme, createThemeObserver, createToggleGroup, createTypingIndicator, createVoiceProvider, createWidgetHostLayout, createXmlParser, initAgentWidget as default, defaultActionHandlers, defaultJsonActionParser, defaultParseRules, detectColorScheme, directivePostprocessor, ensureAskUserQuestionSheet, escapeHtml, extractComponentDirectiveFromMessage, fileToImagePart, formatEnrichedContext, generateAssistantMessageId, generateCodeSnippet, generateMessageId, generateStableSelector, generateUserMessageId, getActiveTheme, getColorScheme, getDisplayText, getHeaderLayout, getImageParts, getPreset, hasComponentDirective, hasImages, headerLayouts, highContrastPlugin, initAgentWidget, isAskUserQuestionMessage, isComponentDirectiveType, isDockedMountMode, isVoiceSupported, listRegisteredStreamAnimations, markdownPostprocessor, mergeWithDefaults, normalizeContent, parseAskUserQuestionPayload, pluginRegistry, reducedMotionPlugin, registerStreamAnimationPlugin, removeAskUserQuestionSheet, renderComponentDirective, renderLoadingIndicatorWithFallback, renderLucideIcon, resolveDockConfig, resolveSanitizer, resolveTokens, themeToCssVariables, unregisterStreamAnimationPlugin, validateImageFile, validateTheme };
6781
+ export { ASK_USER_QUESTION_TOOL_NAME, type AgentConfig, type AgentExecutionState, type AgentLoopConfig, type AgentMessageMetadata, type AgentRequestOptions, type AgentToolsConfig, type AgentWidgetAgentRequestPayload, type AgentWidgetApproval, type AgentWidgetApprovalConfig, type AgentWidgetArtifactsFeature, type AgentWidgetArtifactsLayoutConfig, type AgentWidgetAskUserQuestionFeature, type AgentWidgetAskUserQuestionStyles, type AgentWidgetAttachmentsConfig, type AgentWidgetAvatarConfig, AgentWidgetClient, type AgentWidgetComposerConfig, type AgentWidgetConfig, type AgentWidgetController, type AgentWidgetControllerEventMap, type AgentWidgetCustomFetch, type AgentWidgetDockConfig, type AgentWidgetEvent, type AgentWidgetFeatureFlags, type AgentWidgetHeaderLayoutConfig, type AgentWidgetHeadersFunction, type AgentWidgetInitHandle, type AgentWidgetInitOptions, type AgentWidgetLauncherConfig, type AgentWidgetLayoutConfig, type AgentWidgetLoadingIndicatorConfig, type AgentWidgetMarkdownConfig, type AgentWidgetMarkdownOptions, type AgentWidgetMarkdownRendererOverrides, type AgentWidgetMessage, type AgentWidgetMessageActionsConfig, type AgentWidgetMessageFeedback, type AgentWidgetMessageLayoutConfig, type AgentWidgetPlugin, type AgentWidgetRequestPayload, type AgentWidgetSSEEventParser, type AgentWidgetSSEEventResult, AgentWidgetSession, type AgentWidgetSessionStatus, type AgentWidgetStreamAnimationBuffer, type AgentWidgetStreamAnimationBuiltinType, type AgentWidgetStreamAnimationFeature, type AgentWidgetStreamAnimationPlaceholder, type AgentWidgetStreamAnimationType, type AgentWidgetStreamParser, type AgentWidgetStreamParserResult, type AgentWidgetTimestampConfig, type ArtifactConfigPayload, type ArtifactPaneTokens, type ArtifactTabTokens, type ArtifactToolbarTokens, type AskUserQuestionOption, type AskUserQuestionPayload, type AskUserQuestionPrompt, AttachmentManager, type AttachmentManagerConfig, type BorderScale, type CSATFeedbackOptions, type ClientChatRequest, type ClientFeedbackRequest, type ClientFeedbackType, type ClientInitResponse, type ClientSession, type CodeFormat, type CodeGeneratorHooks, type CodeGeneratorOptions, type ColorPalette, type ColorShade, type ComboButtonHandle, type ComponentContext, type ComponentDirective, type ComponentRenderer, type ComponentTokens, type ComposerBuildContext, type ComposerElements, type ContentPart, type CreateComboButtonOptions, type CreateDropdownOptions, type CreateIconButtonOptions, type CreateLabelButtonOptions, type CreateStandardBubbleOptions, type CreateThemeOptions, type CreateToggleGroupOptions, DEFAULT_COMPONENTS, DEFAULT_FLOATING_LAUNCHER_MAX_WIDTH, DEFAULT_FLOATING_LAUNCHER_WIDTH, DEFAULT_PALETTE, DEFAULT_SEMANTIC, DEFAULT_WIDGET_CONFIG, type DeepPartial, type DemoCarouselHandle, type DemoCarouselItem, type DemoCarouselOptions, type DomContextMode, type DomContextOptions, type DropdownMenuHandle, type DropdownMenuItem, type EnrichedPageElement, type EventStreamBadgeColor, type EventStreamConfig, type EventStreamPayloadRenderContext, type EventStreamRowRenderContext, type EventStreamToolbarRenderContext, type EventStreamViewRenderContext, type FormatEnrichedContextOptions, type HeaderBuildContext, type HeaderElements, type HeaderLayoutContext, type HeaderLayoutRenderer, type HeaderRenderContext, type IconButtonTokens, type IconName, type IdleIndicatorRenderContext, type ImageContentPart, type InjectAssistantMessageOptions, type InjectComponentDirectiveOptions, type InjectMessageOptions, type InjectSystemMessageOptions, type InjectUserMessageOptions, type LabelButtonTokens, type LoadingIndicatorRenderContext, type LoadingIndicatorRenderer, type MarkdownProcessorOptions, type MessageActionCallbacks, type MessageContent, type MessageRenderContext, type MessageTransform, type NPSFeedbackOptions, PRESETS, PRESET_FULLSCREEN, PRESET_MINIMAL, PRESET_SHOP, type ParseOptionsConfig, type ParseRule, type PendingAttachment, type PersonaArtifactKind, type PersonaArtifactManualUpsert, type PersonaArtifactRecord, type PersonaTheme, type PersonaThemePlugin, type RadiusScale, type RuleScoringContext, type SSEEventCallback, type SSEEventRecord, type SanitizeFunction, type SemanticColors, type SemanticSpacing, type SemanticTypography, type ShadowScale, type SlotRenderContext, type SlotRenderer, type SpacingScale, type StreamAnimationContext, type StreamAnimationPlugin, THEME_ZONES, type TextContentPart, type ThemeValidationError, type ThemeValidationResult, type ThemeZone, type ToggleGroupHandle, type ToggleGroupItem, type ToggleGroupTokens, type TokenReference, type TypographyScale, VERSION, type VoiceConfig, type VoiceProvider, type VoiceResult, type VoiceStatus, type WidgetHostLayout, type WidgetHostLayoutMode, type WidgetLayoutSlot, type WidgetPreset, accessibilityPlugin, animationsPlugin, applyThemeVariables, attachHeaderToContainer, brandPlugin, buildComposer, buildDefaultHeader, buildHeader, buildHeaderWithLayout, buildMinimalHeader, collectEnrichedPageContext, componentRegistry, createActionManager, createAgentExperience, createAskUserQuestionBubble, createBestAvailableVoiceProvider, createBubbleWithLayout, createCSATFeedback, createComboButton, createComponentMiddleware, createComponentStreamParser, createDefaultSanitizer, createDemoCarousel, createDirectivePostprocessor, createDropdownMenu, createFlexibleJsonStreamParser, createIconButton, createImagePart, createJsonStreamParser, createLabelButton, createLocalStorageAdapter, createMarkdownProcessor, createMarkdownProcessorFromConfig, createMessageActions, createNPSFeedback, createPlainTextParser, createPlugin, createRegexJsonParser, createStandardBubble, createTextPart, createTheme, createThemeObserver, createToggleGroup, createTypingIndicator, createVoiceProvider, createWidgetHostLayout, createXmlParser, initAgentWidget as default, defaultActionHandlers, defaultJsonActionParser, defaultParseRules, detectColorScheme, directivePostprocessor, ensureAskUserQuestionSheet, escapeHtml, extractComponentDirectiveFromMessage, fileToImagePart, formatEnrichedContext, generateAssistantMessageId, generateCodeSnippet, generateMessageId, generateStableSelector, generateUserMessageId, getActiveTheme, getColorScheme, getDisplayText, getHeaderLayout, getImageParts, getPreset, hasComponentDirective, hasImages, headerLayouts, highContrastPlugin, initAgentWidget, isAskUserQuestionMessage, isComponentDirectiveType, isDockedMountMode, isVoiceSupported, listRegisteredStreamAnimations, markdownPostprocessor, mergeWithDefaults, normalizeContent, parseAskUserQuestionPayload, pluginRegistry, reducedMotionPlugin, registerStreamAnimationPlugin, removeAskUserQuestionSheet, renderComponentDirective, renderLoadingIndicatorWithFallback, renderLucideIcon, resolveDockConfig, resolveSanitizer, resolveTokens, themeToCssVariables, unregisterStreamAnimationPlugin, validateImageFile, validateTheme };
package/dist/index.d.ts CHANGED
@@ -757,10 +757,28 @@ type FileContentPart = {
757
757
  mimeType: string;
758
758
  filename: string;
759
759
  };
760
+ /**
761
+ * Audio content part for multi-modal messages
762
+ * Supports base64 data URIs or URLs
763
+ */
764
+ type AudioContentPart = {
765
+ type: 'audio';
766
+ audio: string;
767
+ mimeType?: string;
768
+ };
769
+ /**
770
+ * Video content part for multi-modal messages
771
+ * Supports base64 data URIs or URLs
772
+ */
773
+ type VideoContentPart = {
774
+ type: 'video';
775
+ video: string;
776
+ mimeType?: string;
777
+ };
760
778
  /**
761
779
  * Union type for all content part types
762
780
  */
763
- type ContentPart = TextContentPart | ImageContentPart | FileContentPart;
781
+ type ContentPart = TextContentPart | ImageContentPart | FileContentPart | AudioContentPart | VideoContentPart;
764
782
  /**
765
783
  * Message content can be a simple string or an array of content parts
766
784
  */
@@ -4266,6 +4284,22 @@ type InjectMessageOptions = {
4266
4284
  * Consumers can detect this in `messageTransform` to render custom UI.
4267
4285
  */
4268
4286
  voiceProcessing?: boolean;
4287
+ /**
4288
+ * Raw structured payload (typically a JSON string) representing the
4289
+ * full directive that produced this message — e.g. `{ "text": "...",
4290
+ * "component": "Foo", "props": {...} }`.
4291
+ *
4292
+ * Mirrors the field populated by stream parsers during normal LLM
4293
+ * responses. Set this when injecting a message that should render as a
4294
+ * component directive (`hasComponentDirective` /
4295
+ * `extractComponentDirectiveFromMessage` look at `rawContent` first).
4296
+ *
4297
+ * Priority for the API payload remains:
4298
+ * `contentParts > llmContent > rawContent > content`. Pass `llmContent`
4299
+ * alongside `rawContent` if the LLM should see something other than the
4300
+ * raw directive.
4301
+ */
4302
+ rawContent?: string;
4269
4303
  };
4270
4304
  /**
4271
4305
  * Options for injecting assistant messages (most common case).
@@ -4282,6 +4316,57 @@ type InjectUserMessageOptions = Omit<InjectMessageOptions, "role">;
4282
4316
  * Role defaults to 'system'.
4283
4317
  */
4284
4318
  type InjectSystemMessageOptions = Omit<InjectMessageOptions, "role">;
4319
+ /**
4320
+ * Options for injecting an assistant message that renders as a component
4321
+ * directive — sugar over `injectAssistantMessage` for the common case of
4322
+ * "render this registered component, same as if the LLM had emitted it".
4323
+ *
4324
+ * Equivalent to calling `injectAssistantMessage({ content: text, rawContent:
4325
+ * JSON.stringify({ text, component, props }), llmContent })`.
4326
+ *
4327
+ * @example
4328
+ * widget.injectComponentDirective({
4329
+ * component: "DynamicForm",
4330
+ * props: { title: "Book a demo", fields: [...] },
4331
+ * text: "Share your details to book a demo.",
4332
+ * llmContent: "[Showed booking form]"
4333
+ * });
4334
+ */
4335
+ type InjectComponentDirectiveOptions = {
4336
+ /**
4337
+ * Name of a renderer registered via `componentRegistry.register(...)`.
4338
+ */
4339
+ component: string;
4340
+ /**
4341
+ * Props passed to the component renderer.
4342
+ */
4343
+ props?: Record<string, unknown>;
4344
+ /**
4345
+ * Bubble copy displayed above (or with) the rendered component.
4346
+ * Mirrors the `text` field in a streamed JSON directive.
4347
+ * @default ""
4348
+ */
4349
+ text?: string;
4350
+ /**
4351
+ * Content sent to the LLM in API requests. When omitted, the raw
4352
+ * directive JSON is what the LLM would see (per the standard
4353
+ * priority chain). Provide a redacted/short version to avoid sending
4354
+ * the full directive in subsequent turns.
4355
+ */
4356
+ llmContent?: string;
4357
+ /**
4358
+ * Optional message ID. If omitted, an assistant id is auto-generated.
4359
+ */
4360
+ id?: string;
4361
+ /**
4362
+ * Optional creation timestamp (ISO string). If omitted, uses current time.
4363
+ */
4364
+ createdAt?: string;
4365
+ /**
4366
+ * Optional sequence number for ordering.
4367
+ */
4368
+ sequence?: number;
4369
+ };
4285
4370
  type PersonaArtifactRecord = {
4286
4371
  id: string;
4287
4372
  artifactType: PersonaArtifactKind;
@@ -4738,6 +4823,24 @@ declare class AgentWidgetSession {
4738
4823
  * Inject multiple messages in a single batch with one sort and one render pass.
4739
4824
  */
4740
4825
  injectMessageBatch(optionsList: InjectMessageOptions[]): AgentWidgetMessage[];
4826
+ /**
4827
+ * Convenience method for injecting a registered component directive as
4828
+ * an assistant message — the same shape Persona produces from a streamed
4829
+ * `{ "text": "...", "component": "...", "props": {...} }` payload.
4830
+ *
4831
+ * Sets `content` to `text`, `rawContent` to the JSON directive (so
4832
+ * `extractComponentDirectiveFromMessage` can find it), and forwards
4833
+ * `llmContent` / `id` / `createdAt` / `sequence`.
4834
+ *
4835
+ * @example
4836
+ * session.injectComponentDirective({
4837
+ * component: "DynamicForm",
4838
+ * props: { title: "Book a demo", fields: [...] },
4839
+ * text: "Share your details to book a demo.",
4840
+ * llmContent: "[Showed booking form]"
4841
+ * });
4842
+ */
4843
+ injectComponentDirective(options: InjectComponentDirectiveOptions): AgentWidgetMessage;
4741
4844
  sendMessage(rawInput: string, options?: {
4742
4845
  viaVoice?: boolean;
4743
4846
  /** Multi-modal content parts (e.g., images) to include with the message */
@@ -4931,6 +5034,12 @@ type Controller = {
4931
5034
  * Inject multiple messages in a single batch with one sort and one render pass.
4932
5035
  */
4933
5036
  injectMessageBatch: (optionsList: InjectMessageOptions[]) => AgentWidgetMessage[];
5037
+ /**
5038
+ * Convenience method for injecting an assistant message that renders as a
5039
+ * registered component — same shape Persona produces from a streamed
5040
+ * `{ "text": "...", "component": "...", "props": {...} }` payload.
5041
+ */
5042
+ injectComponentDirective: (options: InjectComponentDirectiveOptions) => AgentWidgetMessage;
4934
5043
  /**
4935
5044
  * @deprecated Use injectMessage() instead.
4936
5045
  */
@@ -6504,11 +6613,20 @@ declare function createComponentMiddleware(): {
6504
6613
  reset: () => void;
6505
6614
  };
6506
6615
  /**
6507
- * Checks if a message contains a component directive in its raw content
6616
+ * Checks if a message contains a component directive.
6617
+ *
6618
+ * Looks at `rawContent` first (the field set by stream parsers); falls back
6619
+ * to `content` when it looks like JSON, so injected messages that pass the
6620
+ * directive via `content` (or have no `rawContent`) are still recognized.
6508
6621
  */
6509
6622
  declare function hasComponentDirective(message: AgentWidgetMessage): boolean;
6510
6623
  /**
6511
- * Extracts component directive from a complete message
6624
+ * Extracts component directive from a complete message.
6625
+ *
6626
+ * Looks at `rawContent` first (the field set by stream parsers); falls back
6627
+ * to `content` when it looks like JSON, so injected messages that pass the
6628
+ * directive via `content` (or have no `rawContent`) render the same as
6629
+ * streamed ones.
6512
6630
  */
6513
6631
  declare function extractComponentDirectiveFromMessage(message: AgentWidgetMessage): ComponentDirective | null;
6514
6632
 
@@ -6660,4 +6778,4 @@ declare function createVoiceProvider(config: VoiceConfig): VoiceProvider;
6660
6778
  declare function createBestAvailableVoiceProvider(config?: Partial<VoiceConfig>): VoiceProvider;
6661
6779
  declare function isVoiceSupported(config?: Partial<VoiceConfig>): boolean;
6662
6780
 
6663
- export { ASK_USER_QUESTION_TOOL_NAME, type AgentConfig, type AgentExecutionState, type AgentLoopConfig, type AgentMessageMetadata, type AgentRequestOptions, type AgentToolsConfig, type AgentWidgetAgentRequestPayload, type AgentWidgetApproval, type AgentWidgetApprovalConfig, type AgentWidgetArtifactsFeature, type AgentWidgetArtifactsLayoutConfig, type AgentWidgetAskUserQuestionFeature, type AgentWidgetAskUserQuestionStyles, type AgentWidgetAttachmentsConfig, type AgentWidgetAvatarConfig, AgentWidgetClient, type AgentWidgetComposerConfig, type AgentWidgetConfig, type AgentWidgetController, type AgentWidgetControllerEventMap, type AgentWidgetCustomFetch, type AgentWidgetDockConfig, type AgentWidgetEvent, type AgentWidgetFeatureFlags, type AgentWidgetHeaderLayoutConfig, type AgentWidgetHeadersFunction, type AgentWidgetInitHandle, type AgentWidgetInitOptions, type AgentWidgetLauncherConfig, type AgentWidgetLayoutConfig, type AgentWidgetLoadingIndicatorConfig, type AgentWidgetMarkdownConfig, type AgentWidgetMarkdownOptions, type AgentWidgetMarkdownRendererOverrides, type AgentWidgetMessage, type AgentWidgetMessageActionsConfig, type AgentWidgetMessageFeedback, type AgentWidgetMessageLayoutConfig, type AgentWidgetPlugin, type AgentWidgetRequestPayload, type AgentWidgetSSEEventParser, type AgentWidgetSSEEventResult, AgentWidgetSession, type AgentWidgetSessionStatus, type AgentWidgetStreamAnimationBuffer, type AgentWidgetStreamAnimationBuiltinType, type AgentWidgetStreamAnimationFeature, type AgentWidgetStreamAnimationPlaceholder, type AgentWidgetStreamAnimationType, type AgentWidgetStreamParser, type AgentWidgetStreamParserResult, type AgentWidgetTimestampConfig, type ArtifactConfigPayload, type ArtifactPaneTokens, type ArtifactTabTokens, type ArtifactToolbarTokens, type AskUserQuestionOption, type AskUserQuestionPayload, type AskUserQuestionPrompt, AttachmentManager, type AttachmentManagerConfig, type BorderScale, type CSATFeedbackOptions, type ClientChatRequest, type ClientFeedbackRequest, type ClientFeedbackType, type ClientInitResponse, type ClientSession, type CodeFormat, type CodeGeneratorHooks, type CodeGeneratorOptions, type ColorPalette, type ColorShade, type ComboButtonHandle, type ComponentContext, type ComponentDirective, type ComponentRenderer, type ComponentTokens, type ComposerBuildContext, type ComposerElements, type ContentPart, type CreateComboButtonOptions, type CreateDropdownOptions, type CreateIconButtonOptions, type CreateLabelButtonOptions, type CreateStandardBubbleOptions, type CreateThemeOptions, type CreateToggleGroupOptions, DEFAULT_COMPONENTS, DEFAULT_FLOATING_LAUNCHER_MAX_WIDTH, DEFAULT_FLOATING_LAUNCHER_WIDTH, DEFAULT_PALETTE, DEFAULT_SEMANTIC, DEFAULT_WIDGET_CONFIG, type DeepPartial, type DemoCarouselHandle, type DemoCarouselItem, type DemoCarouselOptions, type DomContextMode, type DomContextOptions, type DropdownMenuHandle, type DropdownMenuItem, type EnrichedPageElement, type EventStreamBadgeColor, type EventStreamConfig, type EventStreamPayloadRenderContext, type EventStreamRowRenderContext, type EventStreamToolbarRenderContext, type EventStreamViewRenderContext, type FormatEnrichedContextOptions, type HeaderBuildContext, type HeaderElements, type HeaderLayoutContext, type HeaderLayoutRenderer, type HeaderRenderContext, type IconButtonTokens, type IconName, type IdleIndicatorRenderContext, type ImageContentPart, type InjectAssistantMessageOptions, type InjectMessageOptions, type InjectSystemMessageOptions, type InjectUserMessageOptions, type LabelButtonTokens, type LoadingIndicatorRenderContext, type LoadingIndicatorRenderer, type MarkdownProcessorOptions, type MessageActionCallbacks, type MessageContent, type MessageRenderContext, type MessageTransform, type NPSFeedbackOptions, PRESETS, PRESET_FULLSCREEN, PRESET_MINIMAL, PRESET_SHOP, type ParseOptionsConfig, type ParseRule, type PendingAttachment, type PersonaArtifactKind, type PersonaArtifactManualUpsert, type PersonaArtifactRecord, type PersonaTheme, type PersonaThemePlugin, type RadiusScale, type RuleScoringContext, type SSEEventCallback, type SSEEventRecord, type SanitizeFunction, type SemanticColors, type SemanticSpacing, type SemanticTypography, type ShadowScale, type SlotRenderContext, type SlotRenderer, type SpacingScale, type StreamAnimationContext, type StreamAnimationPlugin, THEME_ZONES, type TextContentPart, type ThemeValidationError, type ThemeValidationResult, type ThemeZone, type ToggleGroupHandle, type ToggleGroupItem, type ToggleGroupTokens, type TokenReference, type TypographyScale, VERSION, type VoiceConfig, type VoiceProvider, type VoiceResult, type VoiceStatus, type WidgetHostLayout, type WidgetHostLayoutMode, type WidgetLayoutSlot, type WidgetPreset, accessibilityPlugin, animationsPlugin, applyThemeVariables, attachHeaderToContainer, brandPlugin, buildComposer, buildDefaultHeader, buildHeader, buildHeaderWithLayout, buildMinimalHeader, collectEnrichedPageContext, componentRegistry, createActionManager, createAgentExperience, createAskUserQuestionBubble, createBestAvailableVoiceProvider, createBubbleWithLayout, createCSATFeedback, createComboButton, createComponentMiddleware, createComponentStreamParser, createDefaultSanitizer, createDemoCarousel, createDirectivePostprocessor, createDropdownMenu, createFlexibleJsonStreamParser, createIconButton, createImagePart, createJsonStreamParser, createLabelButton, createLocalStorageAdapter, createMarkdownProcessor, createMarkdownProcessorFromConfig, createMessageActions, createNPSFeedback, createPlainTextParser, createPlugin, createRegexJsonParser, createStandardBubble, createTextPart, createTheme, createThemeObserver, createToggleGroup, createTypingIndicator, createVoiceProvider, createWidgetHostLayout, createXmlParser, initAgentWidget as default, defaultActionHandlers, defaultJsonActionParser, defaultParseRules, detectColorScheme, directivePostprocessor, ensureAskUserQuestionSheet, escapeHtml, extractComponentDirectiveFromMessage, fileToImagePart, formatEnrichedContext, generateAssistantMessageId, generateCodeSnippet, generateMessageId, generateStableSelector, generateUserMessageId, getActiveTheme, getColorScheme, getDisplayText, getHeaderLayout, getImageParts, getPreset, hasComponentDirective, hasImages, headerLayouts, highContrastPlugin, initAgentWidget, isAskUserQuestionMessage, isComponentDirectiveType, isDockedMountMode, isVoiceSupported, listRegisteredStreamAnimations, markdownPostprocessor, mergeWithDefaults, normalizeContent, parseAskUserQuestionPayload, pluginRegistry, reducedMotionPlugin, registerStreamAnimationPlugin, removeAskUserQuestionSheet, renderComponentDirective, renderLoadingIndicatorWithFallback, renderLucideIcon, resolveDockConfig, resolveSanitizer, resolveTokens, themeToCssVariables, unregisterStreamAnimationPlugin, validateImageFile, validateTheme };
6781
+ export { ASK_USER_QUESTION_TOOL_NAME, type AgentConfig, type AgentExecutionState, type AgentLoopConfig, type AgentMessageMetadata, type AgentRequestOptions, type AgentToolsConfig, type AgentWidgetAgentRequestPayload, type AgentWidgetApproval, type AgentWidgetApprovalConfig, type AgentWidgetArtifactsFeature, type AgentWidgetArtifactsLayoutConfig, type AgentWidgetAskUserQuestionFeature, type AgentWidgetAskUserQuestionStyles, type AgentWidgetAttachmentsConfig, type AgentWidgetAvatarConfig, AgentWidgetClient, type AgentWidgetComposerConfig, type AgentWidgetConfig, type AgentWidgetController, type AgentWidgetControllerEventMap, type AgentWidgetCustomFetch, type AgentWidgetDockConfig, type AgentWidgetEvent, type AgentWidgetFeatureFlags, type AgentWidgetHeaderLayoutConfig, type AgentWidgetHeadersFunction, type AgentWidgetInitHandle, type AgentWidgetInitOptions, type AgentWidgetLauncherConfig, type AgentWidgetLayoutConfig, type AgentWidgetLoadingIndicatorConfig, type AgentWidgetMarkdownConfig, type AgentWidgetMarkdownOptions, type AgentWidgetMarkdownRendererOverrides, type AgentWidgetMessage, type AgentWidgetMessageActionsConfig, type AgentWidgetMessageFeedback, type AgentWidgetMessageLayoutConfig, type AgentWidgetPlugin, type AgentWidgetRequestPayload, type AgentWidgetSSEEventParser, type AgentWidgetSSEEventResult, AgentWidgetSession, type AgentWidgetSessionStatus, type AgentWidgetStreamAnimationBuffer, type AgentWidgetStreamAnimationBuiltinType, type AgentWidgetStreamAnimationFeature, type AgentWidgetStreamAnimationPlaceholder, type AgentWidgetStreamAnimationType, type AgentWidgetStreamParser, type AgentWidgetStreamParserResult, type AgentWidgetTimestampConfig, type ArtifactConfigPayload, type ArtifactPaneTokens, type ArtifactTabTokens, type ArtifactToolbarTokens, type AskUserQuestionOption, type AskUserQuestionPayload, type AskUserQuestionPrompt, AttachmentManager, type AttachmentManagerConfig, type BorderScale, type CSATFeedbackOptions, type ClientChatRequest, type ClientFeedbackRequest, type ClientFeedbackType, type ClientInitResponse, type ClientSession, type CodeFormat, type CodeGeneratorHooks, type CodeGeneratorOptions, type ColorPalette, type ColorShade, type ComboButtonHandle, type ComponentContext, type ComponentDirective, type ComponentRenderer, type ComponentTokens, type ComposerBuildContext, type ComposerElements, type ContentPart, type CreateComboButtonOptions, type CreateDropdownOptions, type CreateIconButtonOptions, type CreateLabelButtonOptions, type CreateStandardBubbleOptions, type CreateThemeOptions, type CreateToggleGroupOptions, DEFAULT_COMPONENTS, DEFAULT_FLOATING_LAUNCHER_MAX_WIDTH, DEFAULT_FLOATING_LAUNCHER_WIDTH, DEFAULT_PALETTE, DEFAULT_SEMANTIC, DEFAULT_WIDGET_CONFIG, type DeepPartial, type DemoCarouselHandle, type DemoCarouselItem, type DemoCarouselOptions, type DomContextMode, type DomContextOptions, type DropdownMenuHandle, type DropdownMenuItem, type EnrichedPageElement, type EventStreamBadgeColor, type EventStreamConfig, type EventStreamPayloadRenderContext, type EventStreamRowRenderContext, type EventStreamToolbarRenderContext, type EventStreamViewRenderContext, type FormatEnrichedContextOptions, type HeaderBuildContext, type HeaderElements, type HeaderLayoutContext, type HeaderLayoutRenderer, type HeaderRenderContext, type IconButtonTokens, type IconName, type IdleIndicatorRenderContext, type ImageContentPart, type InjectAssistantMessageOptions, type InjectComponentDirectiveOptions, type InjectMessageOptions, type InjectSystemMessageOptions, type InjectUserMessageOptions, type LabelButtonTokens, type LoadingIndicatorRenderContext, type LoadingIndicatorRenderer, type MarkdownProcessorOptions, type MessageActionCallbacks, type MessageContent, type MessageRenderContext, type MessageTransform, type NPSFeedbackOptions, PRESETS, PRESET_FULLSCREEN, PRESET_MINIMAL, PRESET_SHOP, type ParseOptionsConfig, type ParseRule, type PendingAttachment, type PersonaArtifactKind, type PersonaArtifactManualUpsert, type PersonaArtifactRecord, type PersonaTheme, type PersonaThemePlugin, type RadiusScale, type RuleScoringContext, type SSEEventCallback, type SSEEventRecord, type SanitizeFunction, type SemanticColors, type SemanticSpacing, type SemanticTypography, type ShadowScale, type SlotRenderContext, type SlotRenderer, type SpacingScale, type StreamAnimationContext, type StreamAnimationPlugin, THEME_ZONES, type TextContentPart, type ThemeValidationError, type ThemeValidationResult, type ThemeZone, type ToggleGroupHandle, type ToggleGroupItem, type ToggleGroupTokens, type TokenReference, type TypographyScale, VERSION, type VoiceConfig, type VoiceProvider, type VoiceResult, type VoiceStatus, type WidgetHostLayout, type WidgetHostLayoutMode, type WidgetLayoutSlot, type WidgetPreset, accessibilityPlugin, animationsPlugin, applyThemeVariables, attachHeaderToContainer, brandPlugin, buildComposer, buildDefaultHeader, buildHeader, buildHeaderWithLayout, buildMinimalHeader, collectEnrichedPageContext, componentRegistry, createActionManager, createAgentExperience, createAskUserQuestionBubble, createBestAvailableVoiceProvider, createBubbleWithLayout, createCSATFeedback, createComboButton, createComponentMiddleware, createComponentStreamParser, createDefaultSanitizer, createDemoCarousel, createDirectivePostprocessor, createDropdownMenu, createFlexibleJsonStreamParser, createIconButton, createImagePart, createJsonStreamParser, createLabelButton, createLocalStorageAdapter, createMarkdownProcessor, createMarkdownProcessorFromConfig, createMessageActions, createNPSFeedback, createPlainTextParser, createPlugin, createRegexJsonParser, createStandardBubble, createTextPart, createTheme, createThemeObserver, createToggleGroup, createTypingIndicator, createVoiceProvider, createWidgetHostLayout, createXmlParser, initAgentWidget as default, defaultActionHandlers, defaultJsonActionParser, defaultParseRules, detectColorScheme, directivePostprocessor, ensureAskUserQuestionSheet, escapeHtml, extractComponentDirectiveFromMessage, fileToImagePart, formatEnrichedContext, generateAssistantMessageId, generateCodeSnippet, generateMessageId, generateStableSelector, generateUserMessageId, getActiveTheme, getColorScheme, getDisplayText, getHeaderLayout, getImageParts, getPreset, hasComponentDirective, hasImages, headerLayouts, highContrastPlugin, initAgentWidget, isAskUserQuestionMessage, isComponentDirectiveType, isDockedMountMode, isVoiceSupported, listRegisteredStreamAnimations, markdownPostprocessor, mergeWithDefaults, normalizeContent, parseAskUserQuestionPayload, pluginRegistry, reducedMotionPlugin, registerStreamAnimationPlugin, removeAskUserQuestionSheet, renderComponentDirective, renderLoadingIndicatorWithFallback, renderLucideIcon, resolveDockConfig, resolveSanitizer, resolveTokens, themeToCssVariables, unregisterStreamAnimationPlugin, validateImageFile, validateTheme };