@frankieai/react 0.2.8 → 0.2.9

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
@@ -1,5 +1,5 @@
1
1
  import * as react from 'react';
2
- import { ReactNode, CSSProperties, ButtonHTMLAttributes, HTMLAttributes, TextareaHTMLAttributes } from 'react';
2
+ import { ReactNode, CSSProperties, MutableRefObject, ButtonHTMLAttributes, HTMLAttributes, TextareaHTMLAttributes } from 'react';
3
3
  import { PublicWidgetConfig, CreateSessionResponse, ChatAttachment, FrankieServerEvent, WidgetTheme, LoadedSkill, ApiToolInventory } from '@frankieai/core';
4
4
  export { FrankieServerEvent, PublicWidgetConfig, WidgetTheme } from '@frankieai/core';
5
5
  import * as class_variance_authority_types from 'class-variance-authority/types';
@@ -265,8 +265,10 @@ interface ComposerProps {
265
265
  attachments?: ComposerAttachmentsConfig;
266
266
  /** Enables a model dropdown when provided with at least one model. */
267
267
  modelPicker?: ComposerModelPicker;
268
+ /** Populated with a function that focuses the input, so a "type your own" choice can jump here. */
269
+ focusHandleRef?: MutableRefObject<(() => void) | null>;
268
270
  }
269
- declare function Composer({ onSend, onStop, busy, placeholder, disabled, autoFocus, attachments, modelPicker }: ComposerProps): react.JSX.Element;
271
+ declare function Composer({ onSend, onStop, busy, placeholder, disabled, autoFocus, attachments, modelPicker, focusHandleRef }: ComposerProps): react.JSX.Element;
270
272
 
271
273
  interface MessageBubbleProps {
272
274
  message: ChatMessage;
@@ -274,22 +276,47 @@ interface MessageBubbleProps {
274
276
  avatarUrl?: string;
275
277
  showToolActivity: boolean;
276
278
  renderTool?: (tool: ToolActivity) => ReactNode;
279
+ /** Send a picked choice as the next message. Omitted when the host renders its own. */
280
+ onChoose?: (choice: string) => void;
281
+ /** Focus the composer so the user can type their own answer instead of picking. */
282
+ onRequestInput?: () => void;
283
+ /** True only for the newest message, so stale choices from earlier turns aren't clickable. */
284
+ active?: boolean;
285
+ /** A turn is in flight, so choices should be disabled. */
286
+ busy?: boolean;
277
287
  }
278
- declare function MessageBubble({ message, assistantName, avatarUrl, showToolActivity, renderTool, }: MessageBubbleProps): react.JSX.Element;
288
+ declare const MessageBubble: react.NamedExoticComponent<MessageBubbleProps>;
279
289
  declare function TypingDots(): react.JSX.Element;
280
290
 
281
291
  /**
282
- * A deliberately small Markdown subset — paragraphs, lists, fenced code, bold,
283
- * italic, inline code and links.
292
+ * A deliberately small Markdown subset — headings, paragraphs, lists, fenced
293
+ * code, bold, italic, inline code and links.
284
294
  *
285
295
  * Everything is rendered as React elements; nothing goes through
286
296
  * `dangerouslySetInnerHTML`. Model output lands in someone else's production
287
297
  * page, so it is never trusted as markup.
298
+ *
299
+ * Memoized on `text`: while a reply streams, the parent re-renders every frame,
300
+ * but the block tree is only recomputed when the text actually grows — the
301
+ * settled messages above never re-parse at all.
288
302
  */
289
- declare function Markdown({ text, className }: {
303
+ declare const Markdown: react.NamedExoticComponent<{
290
304
  text: string;
291
305
  className?: string;
292
- }): react.JSX.Element;
306
+ }>;
307
+
308
+ /**
309
+ * Clickable answer options the agent offered via a `frankie:choices` block.
310
+ * Picking one sends it as the next message. A trailing "Something else" row
311
+ * doesn't send — it moves the caret to the composer so the user can type their
312
+ * own answer, while the offered options stay put in case they change their mind.
313
+ */
314
+ declare function Choices({ options, onPick, onSomethingElse, disabled, }: {
315
+ options: string[];
316
+ onPick: (choice: string) => void;
317
+ onSomethingElse?: () => void;
318
+ disabled?: boolean;
319
+ }): react.JSX.Element | null;
293
320
 
294
321
  declare function SuggestedPrompts({ prompts, onPick, disabled, }: {
295
322
  prompts: string[];
@@ -351,6 +378,31 @@ declare function Separator({ className }: {
351
378
  /** `forwardRef` rather than React 19's ref-as-prop, so React 18 hosts work too. */
352
379
  declare const Textarea: react.ForwardRefExoticComponent<TextareaHTMLAttributes<HTMLTextAreaElement> & react.RefAttributes<HTMLTextAreaElement>>;
353
380
 
381
+ /**
382
+ * Interactive choice blocks.
383
+ *
384
+ * The agent can end a reply with a fenced block to offer the user a small set
385
+ * of discrete answers:
386
+ *
387
+ * ```frankie:choices
388
+ * British
389
+ * Indian
390
+ * Australian
391
+ * ```
392
+ *
393
+ * The SDK lifts that block out of the prose and renders it as clickable options
394
+ * (the composer stays open, so the user can always type their own answer). The
395
+ * block is a plain fenced code block, so a host that doesn't understand it just
396
+ * shows a harmless code listing instead — never broken markup.
397
+ */
398
+ interface ExtractedChoices {
399
+ /** The reply text with the choices block removed. */
400
+ body: string;
401
+ /** The offered options, or null when there is no complete block. */
402
+ options: string[] | null;
403
+ }
404
+ declare function extractChoices(text: string): ExtractedChoices;
405
+
354
406
  /**
355
407
  * Map a theme to the CSS custom properties the widget's styles read.
356
408
  *
@@ -365,4 +417,4 @@ declare function resolveMode(mode: WidgetTheme["mode"]): "light" | "dark";
365
417
  /** shadcn/ui's class helper: conditional classes with Tailwind conflict resolution. */
366
418
  declare function cn(...inputs: ClassValue[]): string;
367
419
 
368
- export { type AssistantChatMessage, Avatar, Badge, Button, type ButtonProps, Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, type ChatMessage, ChatPanel, type ChatPanelProps, Composer, FRANKIE_CLOUD_URL, FrankieApiError, FrankieChatPage, type FrankieChatPageProps, FrankieClient, type FrankieClientOptions, FrankieInline, type FrankieInlineProps, FrankieProvider, type FrankieProviderProps, FrankieWidget, type FrankieWidgetProps, Markdown, type MessageAttachment, MessageBubble, type PageContext, ScrollArea, type SendOptions, Separator, SuggestedPrompts, Textarea, type ToolActivity, ToolActivityList, ToolActivityRow, TypingDots, type UseFrankieChatResult, type UserChatMessage, applyEvent, buttonVariants, cn, newAssistantMessage, newUserMessage, readEventStream, resolveMode, themeToCssVars, useFrankie, useFrankieChat, useFrankieTheme };
420
+ export { type AssistantChatMessage, Avatar, Badge, Button, type ButtonProps, Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, type ChatMessage, ChatPanel, type ChatPanelProps, Choices, Composer, type ExtractedChoices, FRANKIE_CLOUD_URL, FrankieApiError, FrankieChatPage, type FrankieChatPageProps, FrankieClient, type FrankieClientOptions, FrankieInline, type FrankieInlineProps, FrankieProvider, type FrankieProviderProps, FrankieWidget, type FrankieWidgetProps, Markdown, type MessageAttachment, MessageBubble, type PageContext, ScrollArea, type SendOptions, Separator, SuggestedPrompts, Textarea, type ToolActivity, ToolActivityList, ToolActivityRow, TypingDots, type UseFrankieChatResult, type UserChatMessage, applyEvent, buttonVariants, cn, extractChoices, newAssistantMessage, newUserMessage, readEventStream, resolveMode, themeToCssVars, useFrankie, useFrankieChat, useFrankieTheme };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as react from 'react';
2
- import { ReactNode, CSSProperties, ButtonHTMLAttributes, HTMLAttributes, TextareaHTMLAttributes } from 'react';
2
+ import { ReactNode, CSSProperties, MutableRefObject, ButtonHTMLAttributes, HTMLAttributes, TextareaHTMLAttributes } from 'react';
3
3
  import { PublicWidgetConfig, CreateSessionResponse, ChatAttachment, FrankieServerEvent, WidgetTheme, LoadedSkill, ApiToolInventory } from '@frankieai/core';
4
4
  export { FrankieServerEvent, PublicWidgetConfig, WidgetTheme } from '@frankieai/core';
5
5
  import * as class_variance_authority_types from 'class-variance-authority/types';
@@ -265,8 +265,10 @@ interface ComposerProps {
265
265
  attachments?: ComposerAttachmentsConfig;
266
266
  /** Enables a model dropdown when provided with at least one model. */
267
267
  modelPicker?: ComposerModelPicker;
268
+ /** Populated with a function that focuses the input, so a "type your own" choice can jump here. */
269
+ focusHandleRef?: MutableRefObject<(() => void) | null>;
268
270
  }
269
- declare function Composer({ onSend, onStop, busy, placeholder, disabled, autoFocus, attachments, modelPicker }: ComposerProps): react.JSX.Element;
271
+ declare function Composer({ onSend, onStop, busy, placeholder, disabled, autoFocus, attachments, modelPicker, focusHandleRef }: ComposerProps): react.JSX.Element;
270
272
 
271
273
  interface MessageBubbleProps {
272
274
  message: ChatMessage;
@@ -274,22 +276,47 @@ interface MessageBubbleProps {
274
276
  avatarUrl?: string;
275
277
  showToolActivity: boolean;
276
278
  renderTool?: (tool: ToolActivity) => ReactNode;
279
+ /** Send a picked choice as the next message. Omitted when the host renders its own. */
280
+ onChoose?: (choice: string) => void;
281
+ /** Focus the composer so the user can type their own answer instead of picking. */
282
+ onRequestInput?: () => void;
283
+ /** True only for the newest message, so stale choices from earlier turns aren't clickable. */
284
+ active?: boolean;
285
+ /** A turn is in flight, so choices should be disabled. */
286
+ busy?: boolean;
277
287
  }
278
- declare function MessageBubble({ message, assistantName, avatarUrl, showToolActivity, renderTool, }: MessageBubbleProps): react.JSX.Element;
288
+ declare const MessageBubble: react.NamedExoticComponent<MessageBubbleProps>;
279
289
  declare function TypingDots(): react.JSX.Element;
280
290
 
281
291
  /**
282
- * A deliberately small Markdown subset — paragraphs, lists, fenced code, bold,
283
- * italic, inline code and links.
292
+ * A deliberately small Markdown subset — headings, paragraphs, lists, fenced
293
+ * code, bold, italic, inline code and links.
284
294
  *
285
295
  * Everything is rendered as React elements; nothing goes through
286
296
  * `dangerouslySetInnerHTML`. Model output lands in someone else's production
287
297
  * page, so it is never trusted as markup.
298
+ *
299
+ * Memoized on `text`: while a reply streams, the parent re-renders every frame,
300
+ * but the block tree is only recomputed when the text actually grows — the
301
+ * settled messages above never re-parse at all.
288
302
  */
289
- declare function Markdown({ text, className }: {
303
+ declare const Markdown: react.NamedExoticComponent<{
290
304
  text: string;
291
305
  className?: string;
292
- }): react.JSX.Element;
306
+ }>;
307
+
308
+ /**
309
+ * Clickable answer options the agent offered via a `frankie:choices` block.
310
+ * Picking one sends it as the next message. A trailing "Something else" row
311
+ * doesn't send — it moves the caret to the composer so the user can type their
312
+ * own answer, while the offered options stay put in case they change their mind.
313
+ */
314
+ declare function Choices({ options, onPick, onSomethingElse, disabled, }: {
315
+ options: string[];
316
+ onPick: (choice: string) => void;
317
+ onSomethingElse?: () => void;
318
+ disabled?: boolean;
319
+ }): react.JSX.Element | null;
293
320
 
294
321
  declare function SuggestedPrompts({ prompts, onPick, disabled, }: {
295
322
  prompts: string[];
@@ -351,6 +378,31 @@ declare function Separator({ className }: {
351
378
  /** `forwardRef` rather than React 19's ref-as-prop, so React 18 hosts work too. */
352
379
  declare const Textarea: react.ForwardRefExoticComponent<TextareaHTMLAttributes<HTMLTextAreaElement> & react.RefAttributes<HTMLTextAreaElement>>;
353
380
 
381
+ /**
382
+ * Interactive choice blocks.
383
+ *
384
+ * The agent can end a reply with a fenced block to offer the user a small set
385
+ * of discrete answers:
386
+ *
387
+ * ```frankie:choices
388
+ * British
389
+ * Indian
390
+ * Australian
391
+ * ```
392
+ *
393
+ * The SDK lifts that block out of the prose and renders it as clickable options
394
+ * (the composer stays open, so the user can always type their own answer). The
395
+ * block is a plain fenced code block, so a host that doesn't understand it just
396
+ * shows a harmless code listing instead — never broken markup.
397
+ */
398
+ interface ExtractedChoices {
399
+ /** The reply text with the choices block removed. */
400
+ body: string;
401
+ /** The offered options, or null when there is no complete block. */
402
+ options: string[] | null;
403
+ }
404
+ declare function extractChoices(text: string): ExtractedChoices;
405
+
354
406
  /**
355
407
  * Map a theme to the CSS custom properties the widget's styles read.
356
408
  *
@@ -365,4 +417,4 @@ declare function resolveMode(mode: WidgetTheme["mode"]): "light" | "dark";
365
417
  /** shadcn/ui's class helper: conditional classes with Tailwind conflict resolution. */
366
418
  declare function cn(...inputs: ClassValue[]): string;
367
419
 
368
- export { type AssistantChatMessage, Avatar, Badge, Button, type ButtonProps, Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, type ChatMessage, ChatPanel, type ChatPanelProps, Composer, FRANKIE_CLOUD_URL, FrankieApiError, FrankieChatPage, type FrankieChatPageProps, FrankieClient, type FrankieClientOptions, FrankieInline, type FrankieInlineProps, FrankieProvider, type FrankieProviderProps, FrankieWidget, type FrankieWidgetProps, Markdown, type MessageAttachment, MessageBubble, type PageContext, ScrollArea, type SendOptions, Separator, SuggestedPrompts, Textarea, type ToolActivity, ToolActivityList, ToolActivityRow, TypingDots, type UseFrankieChatResult, type UserChatMessage, applyEvent, buttonVariants, cn, newAssistantMessage, newUserMessage, readEventStream, resolveMode, themeToCssVars, useFrankie, useFrankieChat, useFrankieTheme };
420
+ export { type AssistantChatMessage, Avatar, Badge, Button, type ButtonProps, Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, type ChatMessage, ChatPanel, type ChatPanelProps, Choices, Composer, type ExtractedChoices, FRANKIE_CLOUD_URL, FrankieApiError, FrankieChatPage, type FrankieChatPageProps, FrankieClient, type FrankieClientOptions, FrankieInline, type FrankieInlineProps, FrankieProvider, type FrankieProviderProps, FrankieWidget, type FrankieWidgetProps, Markdown, type MessageAttachment, MessageBubble, type PageContext, ScrollArea, type SendOptions, Separator, SuggestedPrompts, Textarea, type ToolActivity, ToolActivityList, ToolActivityRow, TypingDots, type UseFrankieChatResult, type UserChatMessage, applyEvent, buttonVariants, cn, extractChoices, newAssistantMessage, newUserMessage, readEventStream, resolveMode, themeToCssVars, useFrankie, useFrankieChat, useFrankieTheme };