@hsafa/ui-sdk 5.5.7 → 5.5.8

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$1 from 'react';
2
- import React__default, { ComponentType } from 'react';
2
+ import React__default, { Dispatch, SetStateAction, ComponentType } from 'react';
3
3
  import * as react_jsx_runtime from 'react/jsx-runtime';
4
4
 
5
5
  /**
@@ -528,10 +528,78 @@ interface MessageEditorAPI {
528
528
  }
529
529
  declare function useMessageEditor(config: UseMessageEditorConfig): MessageEditorAPI;
530
530
 
531
+ type HsafaActiveChatIdSource = 'context' | 'storage' | 'none';
532
+ interface UseHsafaActiveChatIdOptions {
533
+ agentId: string;
534
+ prefer?: 'context' | 'storage';
535
+ }
536
+ interface HsafaActiveChatIdResult {
537
+ chatId?: string;
538
+ isReady: boolean;
539
+ source: HsafaActiveChatIdSource;
540
+ }
541
+ declare function useHsafaActiveChatId(options: UseHsafaActiveChatIdOptions): HsafaActiveChatIdResult;
542
+
543
+ type HsafaArtifactStoreBackend = 'opfs' | 'localStorage';
544
+ interface HsafaArtifactStoreConfig<T> {
545
+ namespace: string;
546
+ serialize?: (value: T) => string;
547
+ deserialize?: (raw: string) => T;
548
+ storageOrder?: HsafaArtifactStoreBackend[];
549
+ legacyDecode?: (raw: string) => {
550
+ value: T;
551
+ chatId: string;
552
+ versionId: string;
553
+ updatedAt?: string;
554
+ } | null;
555
+ }
556
+ interface HsafaArtifactStore<T> {
557
+ saveLatest: (chatId: string, value: T) => Promise<void>;
558
+ loadLatest: (chatId: string) => Promise<T | null>;
559
+ saveVersion: (chatId: string, versionId: string, value: T) => Promise<void>;
560
+ loadVersion: (chatId: string, versionId: string) => Promise<T | null>;
561
+ hasVersion: (chatId: string, versionId: string) => Promise<boolean>;
562
+ findMostRecentChatId: () => Promise<string | null>;
563
+ }
564
+ declare function createHsafaArtifactStore<T>(config: HsafaArtifactStoreConfig<T>): HsafaArtifactStore<T>;
565
+
566
+ type ChatArtifactStatus = 'idle' | 'loading' | 'ready' | 'error';
567
+ interface UseChatArtifactOptions<T> {
568
+ agentId: string;
569
+ chatId?: string;
570
+ initial: T;
571
+ store: HsafaArtifactStore<T>;
572
+ autoLoad?: boolean;
573
+ autoSave?: boolean;
574
+ saveDebounceMs?: number;
575
+ }
576
+ interface ChatArtifactResult<T> {
577
+ value: T;
578
+ setValue: Dispatch<SetStateAction<T>>;
579
+ status: ChatArtifactStatus;
580
+ error?: unknown;
581
+ reload: () => Promise<void>;
582
+ flushSave: () => Promise<void>;
583
+ }
584
+ declare function useChatArtifact<T>(options: UseChatArtifactOptions<T>): ChatArtifactResult<T>;
585
+
586
+ interface UseChatArtifactVersioningOptions<T> {
587
+ chatId?: string;
588
+ store: HsafaArtifactStore<T>;
589
+ value: T;
590
+ setValue: Dispatch<SetStateAction<T>>;
591
+ initial: T;
592
+ }
593
+ interface ChatArtifactVersioningAPI {
594
+ onFinish: (payload: unknown) => Promise<void>;
595
+ onMessagesChange: (messages: unknown[], chatId?: string) => Promise<void>;
596
+ }
597
+ declare function useChatArtifactVersioning<T>(options: UseChatArtifactVersioningOptions<T>): ChatArtifactVersioningAPI;
598
+
531
599
  /**
532
600
  * Handler function for custom actions that can be triggered by the AI agent
533
601
  */
534
- type HsafaActionHandler = (params: any, meta: {
602
+ type HsafaActionHandler = (params: unknown, meta: {
535
603
  /** Name of the action being called */
536
604
  name: string;
537
605
  /** When the action is being triggered */
@@ -542,7 +610,7 @@ type HsafaActionHandler = (params: any, meta: {
542
610
  assistantMessageId?: string;
543
611
  /** ID of the current chat session */
544
612
  chatId?: string;
545
- }) => Promise<any> | any;
613
+ }) => Promise<unknown> | unknown;
546
614
  /**
547
615
  * Configuration options for the Hsafa SDK
548
616
  */
@@ -561,15 +629,15 @@ interface HsafaContextValue extends HsafaConfig {
561
629
  /** Registered custom actions */
562
630
  actions: Map<string, HsafaActionHandler>;
563
631
  /** Registered custom components */
564
- components: Map<string, React__default.ComponentType<any>>;
632
+ components: Map<string, React__default.ComponentType<Record<string, unknown>>>;
565
633
  /** Register a custom action handler */
566
634
  registerAction: (name: string, handler: HsafaActionHandler) => () => void;
567
635
  /** Unregister a custom action handler */
568
636
  unregisterAction: (name: string, handler?: HsafaActionHandler) => void;
569
637
  /** Register a custom component */
570
- registerComponent: (name: string, component: React__default.ComponentType<any>) => () => void;
638
+ registerComponent: (name: string, component: React__default.ComponentType<Record<string, unknown>>) => () => void;
571
639
  /** Unregister a custom component */
572
- unregisterComponent: (name: string, component?: React__default.ComponentType<any>) => void;
640
+ unregisterComponent: (name: string, component?: React__default.ComponentType<Record<string, unknown>>) => void;
573
641
  /** Global streaming state - true if any chat is streaming */
574
642
  isAnyStreaming: boolean;
575
643
  /** Set streaming state for a specific chat instance */
@@ -582,6 +650,12 @@ interface HsafaContextValue extends HsafaConfig {
582
650
  currentChatId?: string;
583
651
  /** Setter for current chat id */
584
652
  setCurrentChatId: (chatId: string) => void;
653
+ tools: Map<string, HsafaTool>;
654
+ uiComponents: Map<string, React__default.ComponentType<Record<string, unknown>>>;
655
+ registerTool: (name: string, tool: HsafaTool) => () => void;
656
+ unregisterTool: (name: string, tool?: HsafaTool) => void;
657
+ registerUIComponent: (name: string, component: React__default.ComponentType<Record<string, unknown>>) => () => void;
658
+ unregisterUIComponent: (name: string, component?: React__default.ComponentType<Record<string, unknown>>) => void;
585
659
  }
586
660
  /**
587
661
  * Props for the HsafaProvider component
@@ -589,6 +663,8 @@ interface HsafaContextValue extends HsafaConfig {
589
663
  interface HsafaProviderProps extends HsafaConfig {
590
664
  /** Child components that will have access to the Hsafa context */
591
665
  children: React__default.ReactNode;
666
+ tools?: Record<string, HsafaTool>;
667
+ uiComponents?: Record<string, React__default.ComponentType<Record<string, unknown>>>;
592
668
  }
593
669
  /**
594
670
  * Provider component that sets up the Hsafa context for the SDK.
@@ -601,7 +677,7 @@ interface HsafaProviderProps extends HsafaConfig {
601
677
  * </HsafaProvider>
602
678
  * ```
603
679
  */
604
- declare function HsafaProvider({ baseUrl, dir, theme, children }: HsafaProviderProps): react_jsx_runtime.JSX.Element;
680
+ declare function HsafaProvider({ baseUrl, dir, theme, children, tools: initialTools, uiComponents: initialUIComponents }: HsafaProviderProps): react_jsx_runtime.JSX.Element;
605
681
  /**
606
682
  * Hook to access the Hsafa context.
607
683
  * Must be used within a HsafaProvider.
@@ -944,4 +1020,4 @@ type FillResult = {
944
1020
  };
945
1021
  declare function FillActiveInput(value: any, options?: FillInputOptions): Promise<FillResult>;
946
1022
 
947
- export { type Anchor, type Attachment, Button, type ButtonProps, type ChatMessage, type ChatMetadata, type ChatStorageAPI, ContentContainer, type ContentContainerProps, CursorController, type CustomToolUIRenderProps, type DomComponent, type EditProcessContent, FillActiveInput, type FillInputOptions, type FillResult, FloatingChatButton, type GetDomComponentsOptions, type GetDomComponentsResult, type GuideAction, type GuideCursorOptions, type GuideOptions, type GuideRunResult, type GuideStep, type GuideStepResult, type GuideTarget, type HsafaAgentAPI, HsafaChat, type HsafaChatProps, HsafaProvider, type HsafaTool, type MessageEditorAPI, type SavedChat, type UIComponentProps, type UseChatStorageConfig, type UseHsafaAgentConfig, type UseMessageEditorConfig, registry as componentRegistry, guideCursor as controlCursor, getDomComponents, guideCursor, useAutoScroll, useChatStorage, useFileUpload, useHsafa, useHsafaAgent, useMessageEditor };
1023
+ export { type Anchor, type Attachment, Button, type ButtonProps, type ChatArtifactResult, type ChatArtifactStatus, type ChatArtifactVersioningAPI, type ChatMessage, type ChatMetadata, type ChatStorageAPI, ContentContainer, type ContentContainerProps, CursorController, type CustomToolUIRenderProps, type DomComponent, type EditProcessContent, FillActiveInput, type FillInputOptions, type FillResult, FloatingChatButton, type GetDomComponentsOptions, type GetDomComponentsResult, type GuideAction, type GuideCursorOptions, type GuideOptions, type GuideRunResult, type GuideStep, type GuideStepResult, type GuideTarget, type HsafaActiveChatIdResult, type HsafaActiveChatIdSource, type HsafaAgentAPI, type HsafaArtifactStore, type HsafaArtifactStoreBackend, type HsafaArtifactStoreConfig, HsafaChat, type HsafaChatProps, HsafaProvider, type HsafaTool, type MessageEditorAPI, type SavedChat, type UIComponentProps, type UseChatArtifactOptions, type UseChatArtifactVersioningOptions, type UseChatStorageConfig, type UseHsafaActiveChatIdOptions, type UseHsafaAgentConfig, type UseMessageEditorConfig, registry as componentRegistry, guideCursor as controlCursor, createHsafaArtifactStore, getDomComponents, guideCursor, useAutoScroll, useChatArtifact, useChatArtifactVersioning, useChatStorage, useFileUpload, useHsafa, useHsafaActiveChatId, useHsafaAgent, useMessageEditor };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as React$1 from 'react';
2
- import React__default, { ComponentType } from 'react';
2
+ import React__default, { Dispatch, SetStateAction, ComponentType } from 'react';
3
3
  import * as react_jsx_runtime from 'react/jsx-runtime';
4
4
 
5
5
  /**
@@ -528,10 +528,78 @@ interface MessageEditorAPI {
528
528
  }
529
529
  declare function useMessageEditor(config: UseMessageEditorConfig): MessageEditorAPI;
530
530
 
531
+ type HsafaActiveChatIdSource = 'context' | 'storage' | 'none';
532
+ interface UseHsafaActiveChatIdOptions {
533
+ agentId: string;
534
+ prefer?: 'context' | 'storage';
535
+ }
536
+ interface HsafaActiveChatIdResult {
537
+ chatId?: string;
538
+ isReady: boolean;
539
+ source: HsafaActiveChatIdSource;
540
+ }
541
+ declare function useHsafaActiveChatId(options: UseHsafaActiveChatIdOptions): HsafaActiveChatIdResult;
542
+
543
+ type HsafaArtifactStoreBackend = 'opfs' | 'localStorage';
544
+ interface HsafaArtifactStoreConfig<T> {
545
+ namespace: string;
546
+ serialize?: (value: T) => string;
547
+ deserialize?: (raw: string) => T;
548
+ storageOrder?: HsafaArtifactStoreBackend[];
549
+ legacyDecode?: (raw: string) => {
550
+ value: T;
551
+ chatId: string;
552
+ versionId: string;
553
+ updatedAt?: string;
554
+ } | null;
555
+ }
556
+ interface HsafaArtifactStore<T> {
557
+ saveLatest: (chatId: string, value: T) => Promise<void>;
558
+ loadLatest: (chatId: string) => Promise<T | null>;
559
+ saveVersion: (chatId: string, versionId: string, value: T) => Promise<void>;
560
+ loadVersion: (chatId: string, versionId: string) => Promise<T | null>;
561
+ hasVersion: (chatId: string, versionId: string) => Promise<boolean>;
562
+ findMostRecentChatId: () => Promise<string | null>;
563
+ }
564
+ declare function createHsafaArtifactStore<T>(config: HsafaArtifactStoreConfig<T>): HsafaArtifactStore<T>;
565
+
566
+ type ChatArtifactStatus = 'idle' | 'loading' | 'ready' | 'error';
567
+ interface UseChatArtifactOptions<T> {
568
+ agentId: string;
569
+ chatId?: string;
570
+ initial: T;
571
+ store: HsafaArtifactStore<T>;
572
+ autoLoad?: boolean;
573
+ autoSave?: boolean;
574
+ saveDebounceMs?: number;
575
+ }
576
+ interface ChatArtifactResult<T> {
577
+ value: T;
578
+ setValue: Dispatch<SetStateAction<T>>;
579
+ status: ChatArtifactStatus;
580
+ error?: unknown;
581
+ reload: () => Promise<void>;
582
+ flushSave: () => Promise<void>;
583
+ }
584
+ declare function useChatArtifact<T>(options: UseChatArtifactOptions<T>): ChatArtifactResult<T>;
585
+
586
+ interface UseChatArtifactVersioningOptions<T> {
587
+ chatId?: string;
588
+ store: HsafaArtifactStore<T>;
589
+ value: T;
590
+ setValue: Dispatch<SetStateAction<T>>;
591
+ initial: T;
592
+ }
593
+ interface ChatArtifactVersioningAPI {
594
+ onFinish: (payload: unknown) => Promise<void>;
595
+ onMessagesChange: (messages: unknown[], chatId?: string) => Promise<void>;
596
+ }
597
+ declare function useChatArtifactVersioning<T>(options: UseChatArtifactVersioningOptions<T>): ChatArtifactVersioningAPI;
598
+
531
599
  /**
532
600
  * Handler function for custom actions that can be triggered by the AI agent
533
601
  */
534
- type HsafaActionHandler = (params: any, meta: {
602
+ type HsafaActionHandler = (params: unknown, meta: {
535
603
  /** Name of the action being called */
536
604
  name: string;
537
605
  /** When the action is being triggered */
@@ -542,7 +610,7 @@ type HsafaActionHandler = (params: any, meta: {
542
610
  assistantMessageId?: string;
543
611
  /** ID of the current chat session */
544
612
  chatId?: string;
545
- }) => Promise<any> | any;
613
+ }) => Promise<unknown> | unknown;
546
614
  /**
547
615
  * Configuration options for the Hsafa SDK
548
616
  */
@@ -561,15 +629,15 @@ interface HsafaContextValue extends HsafaConfig {
561
629
  /** Registered custom actions */
562
630
  actions: Map<string, HsafaActionHandler>;
563
631
  /** Registered custom components */
564
- components: Map<string, React__default.ComponentType<any>>;
632
+ components: Map<string, React__default.ComponentType<Record<string, unknown>>>;
565
633
  /** Register a custom action handler */
566
634
  registerAction: (name: string, handler: HsafaActionHandler) => () => void;
567
635
  /** Unregister a custom action handler */
568
636
  unregisterAction: (name: string, handler?: HsafaActionHandler) => void;
569
637
  /** Register a custom component */
570
- registerComponent: (name: string, component: React__default.ComponentType<any>) => () => void;
638
+ registerComponent: (name: string, component: React__default.ComponentType<Record<string, unknown>>) => () => void;
571
639
  /** Unregister a custom component */
572
- unregisterComponent: (name: string, component?: React__default.ComponentType<any>) => void;
640
+ unregisterComponent: (name: string, component?: React__default.ComponentType<Record<string, unknown>>) => void;
573
641
  /** Global streaming state - true if any chat is streaming */
574
642
  isAnyStreaming: boolean;
575
643
  /** Set streaming state for a specific chat instance */
@@ -582,6 +650,12 @@ interface HsafaContextValue extends HsafaConfig {
582
650
  currentChatId?: string;
583
651
  /** Setter for current chat id */
584
652
  setCurrentChatId: (chatId: string) => void;
653
+ tools: Map<string, HsafaTool>;
654
+ uiComponents: Map<string, React__default.ComponentType<Record<string, unknown>>>;
655
+ registerTool: (name: string, tool: HsafaTool) => () => void;
656
+ unregisterTool: (name: string, tool?: HsafaTool) => void;
657
+ registerUIComponent: (name: string, component: React__default.ComponentType<Record<string, unknown>>) => () => void;
658
+ unregisterUIComponent: (name: string, component?: React__default.ComponentType<Record<string, unknown>>) => void;
585
659
  }
586
660
  /**
587
661
  * Props for the HsafaProvider component
@@ -589,6 +663,8 @@ interface HsafaContextValue extends HsafaConfig {
589
663
  interface HsafaProviderProps extends HsafaConfig {
590
664
  /** Child components that will have access to the Hsafa context */
591
665
  children: React__default.ReactNode;
666
+ tools?: Record<string, HsafaTool>;
667
+ uiComponents?: Record<string, React__default.ComponentType<Record<string, unknown>>>;
592
668
  }
593
669
  /**
594
670
  * Provider component that sets up the Hsafa context for the SDK.
@@ -601,7 +677,7 @@ interface HsafaProviderProps extends HsafaConfig {
601
677
  * </HsafaProvider>
602
678
  * ```
603
679
  */
604
- declare function HsafaProvider({ baseUrl, dir, theme, children }: HsafaProviderProps): react_jsx_runtime.JSX.Element;
680
+ declare function HsafaProvider({ baseUrl, dir, theme, children, tools: initialTools, uiComponents: initialUIComponents }: HsafaProviderProps): react_jsx_runtime.JSX.Element;
605
681
  /**
606
682
  * Hook to access the Hsafa context.
607
683
  * Must be used within a HsafaProvider.
@@ -944,4 +1020,4 @@ type FillResult = {
944
1020
  };
945
1021
  declare function FillActiveInput(value: any, options?: FillInputOptions): Promise<FillResult>;
946
1022
 
947
- export { type Anchor, type Attachment, Button, type ButtonProps, type ChatMessage, type ChatMetadata, type ChatStorageAPI, ContentContainer, type ContentContainerProps, CursorController, type CustomToolUIRenderProps, type DomComponent, type EditProcessContent, FillActiveInput, type FillInputOptions, type FillResult, FloatingChatButton, type GetDomComponentsOptions, type GetDomComponentsResult, type GuideAction, type GuideCursorOptions, type GuideOptions, type GuideRunResult, type GuideStep, type GuideStepResult, type GuideTarget, type HsafaAgentAPI, HsafaChat, type HsafaChatProps, HsafaProvider, type HsafaTool, type MessageEditorAPI, type SavedChat, type UIComponentProps, type UseChatStorageConfig, type UseHsafaAgentConfig, type UseMessageEditorConfig, registry as componentRegistry, guideCursor as controlCursor, getDomComponents, guideCursor, useAutoScroll, useChatStorage, useFileUpload, useHsafa, useHsafaAgent, useMessageEditor };
1023
+ export { type Anchor, type Attachment, Button, type ButtonProps, type ChatArtifactResult, type ChatArtifactStatus, type ChatArtifactVersioningAPI, type ChatMessage, type ChatMetadata, type ChatStorageAPI, ContentContainer, type ContentContainerProps, CursorController, type CustomToolUIRenderProps, type DomComponent, type EditProcessContent, FillActiveInput, type FillInputOptions, type FillResult, FloatingChatButton, type GetDomComponentsOptions, type GetDomComponentsResult, type GuideAction, type GuideCursorOptions, type GuideOptions, type GuideRunResult, type GuideStep, type GuideStepResult, type GuideTarget, type HsafaActiveChatIdResult, type HsafaActiveChatIdSource, type HsafaAgentAPI, type HsafaArtifactStore, type HsafaArtifactStoreBackend, type HsafaArtifactStoreConfig, HsafaChat, type HsafaChatProps, HsafaProvider, type HsafaTool, type MessageEditorAPI, type SavedChat, type UIComponentProps, type UseChatArtifactOptions, type UseChatArtifactVersioningOptions, type UseChatStorageConfig, type UseHsafaActiveChatIdOptions, type UseHsafaAgentConfig, type UseMessageEditorConfig, registry as componentRegistry, guideCursor as controlCursor, createHsafaArtifactStore, getDomComponents, guideCursor, useAutoScroll, useChatArtifact, useChatArtifactVersioning, useChatStorage, useFileUpload, useHsafa, useHsafaActiveChatId, useHsafaAgent, useMessageEditor };