@hsafa/ui-sdk 5.5.7 → 5.5.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$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,87 @@ 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
+
599
+ declare function useHsafaTools<TState, TTools extends Record<string, unknown>>(config: {
600
+ state: TState;
601
+ setState: React$1.Dispatch<React$1.SetStateAction<TState>>;
602
+ tools: (api: {
603
+ get: () => TState;
604
+ set: React$1.Dispatch<React$1.SetStateAction<TState>>;
605
+ }) => TTools;
606
+ }): TTools;
607
+
531
608
  /**
532
609
  * Handler function for custom actions that can be triggered by the AI agent
533
610
  */
534
- type HsafaActionHandler = (params: any, meta: {
611
+ type HsafaActionHandler = (params: unknown, meta: {
535
612
  /** Name of the action being called */
536
613
  name: string;
537
614
  /** When the action is being triggered */
@@ -542,7 +619,7 @@ type HsafaActionHandler = (params: any, meta: {
542
619
  assistantMessageId?: string;
543
620
  /** ID of the current chat session */
544
621
  chatId?: string;
545
- }) => Promise<any> | any;
622
+ }) => Promise<unknown> | unknown;
546
623
  /**
547
624
  * Configuration options for the Hsafa SDK
548
625
  */
@@ -561,15 +638,15 @@ interface HsafaContextValue extends HsafaConfig {
561
638
  /** Registered custom actions */
562
639
  actions: Map<string, HsafaActionHandler>;
563
640
  /** Registered custom components */
564
- components: Map<string, React__default.ComponentType<any>>;
641
+ components: Map<string, React__default.ComponentType<Record<string, unknown>>>;
565
642
  /** Register a custom action handler */
566
643
  registerAction: (name: string, handler: HsafaActionHandler) => () => void;
567
644
  /** Unregister a custom action handler */
568
645
  unregisterAction: (name: string, handler?: HsafaActionHandler) => void;
569
646
  /** Register a custom component */
570
- registerComponent: (name: string, component: React__default.ComponentType<any>) => () => void;
647
+ registerComponent: (name: string, component: React__default.ComponentType<Record<string, unknown>>) => () => void;
571
648
  /** Unregister a custom component */
572
- unregisterComponent: (name: string, component?: React__default.ComponentType<any>) => void;
649
+ unregisterComponent: (name: string, component?: React__default.ComponentType<Record<string, unknown>>) => void;
573
650
  /** Global streaming state - true if any chat is streaming */
574
651
  isAnyStreaming: boolean;
575
652
  /** Set streaming state for a specific chat instance */
@@ -582,6 +659,12 @@ interface HsafaContextValue extends HsafaConfig {
582
659
  currentChatId?: string;
583
660
  /** Setter for current chat id */
584
661
  setCurrentChatId: (chatId: string) => void;
662
+ tools: Map<string, HsafaTool>;
663
+ uiComponents: Map<string, React__default.ComponentType<Record<string, unknown>>>;
664
+ registerTool: (name: string, tool: HsafaTool) => () => void;
665
+ unregisterTool: (name: string, tool?: HsafaTool) => void;
666
+ registerUIComponent: (name: string, component: React__default.ComponentType<Record<string, unknown>>) => () => void;
667
+ unregisterUIComponent: (name: string, component?: React__default.ComponentType<Record<string, unknown>>) => void;
585
668
  }
586
669
  /**
587
670
  * Props for the HsafaProvider component
@@ -589,6 +672,8 @@ interface HsafaContextValue extends HsafaConfig {
589
672
  interface HsafaProviderProps extends HsafaConfig {
590
673
  /** Child components that will have access to the Hsafa context */
591
674
  children: React__default.ReactNode;
675
+ tools?: Record<string, HsafaTool>;
676
+ uiComponents?: Record<string, React__default.ComponentType<Record<string, unknown>>>;
592
677
  }
593
678
  /**
594
679
  * Provider component that sets up the Hsafa context for the SDK.
@@ -601,7 +686,7 @@ interface HsafaProviderProps extends HsafaConfig {
601
686
  * </HsafaProvider>
602
687
  * ```
603
688
  */
604
- declare function HsafaProvider({ baseUrl, dir, theme, children }: HsafaProviderProps): react_jsx_runtime.JSX.Element;
689
+ declare function HsafaProvider({ baseUrl, dir, theme, children, tools: initialTools, uiComponents: initialUIComponents }: HsafaProviderProps): react_jsx_runtime.JSX.Element;
605
690
  /**
606
691
  * Hook to access the Hsafa context.
607
692
  * Must be used within a HsafaProvider.
@@ -944,4 +1029,4 @@ type FillResult = {
944
1029
  };
945
1030
  declare function FillActiveInput(value: any, options?: FillInputOptions): Promise<FillResult>;
946
1031
 
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 };
1032
+ 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, useHsafaTools, 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,87 @@ 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
+
599
+ declare function useHsafaTools<TState, TTools extends Record<string, unknown>>(config: {
600
+ state: TState;
601
+ setState: React$1.Dispatch<React$1.SetStateAction<TState>>;
602
+ tools: (api: {
603
+ get: () => TState;
604
+ set: React$1.Dispatch<React$1.SetStateAction<TState>>;
605
+ }) => TTools;
606
+ }): TTools;
607
+
531
608
  /**
532
609
  * Handler function for custom actions that can be triggered by the AI agent
533
610
  */
534
- type HsafaActionHandler = (params: any, meta: {
611
+ type HsafaActionHandler = (params: unknown, meta: {
535
612
  /** Name of the action being called */
536
613
  name: string;
537
614
  /** When the action is being triggered */
@@ -542,7 +619,7 @@ type HsafaActionHandler = (params: any, meta: {
542
619
  assistantMessageId?: string;
543
620
  /** ID of the current chat session */
544
621
  chatId?: string;
545
- }) => Promise<any> | any;
622
+ }) => Promise<unknown> | unknown;
546
623
  /**
547
624
  * Configuration options for the Hsafa SDK
548
625
  */
@@ -561,15 +638,15 @@ interface HsafaContextValue extends HsafaConfig {
561
638
  /** Registered custom actions */
562
639
  actions: Map<string, HsafaActionHandler>;
563
640
  /** Registered custom components */
564
- components: Map<string, React__default.ComponentType<any>>;
641
+ components: Map<string, React__default.ComponentType<Record<string, unknown>>>;
565
642
  /** Register a custom action handler */
566
643
  registerAction: (name: string, handler: HsafaActionHandler) => () => void;
567
644
  /** Unregister a custom action handler */
568
645
  unregisterAction: (name: string, handler?: HsafaActionHandler) => void;
569
646
  /** Register a custom component */
570
- registerComponent: (name: string, component: React__default.ComponentType<any>) => () => void;
647
+ registerComponent: (name: string, component: React__default.ComponentType<Record<string, unknown>>) => () => void;
571
648
  /** Unregister a custom component */
572
- unregisterComponent: (name: string, component?: React__default.ComponentType<any>) => void;
649
+ unregisterComponent: (name: string, component?: React__default.ComponentType<Record<string, unknown>>) => void;
573
650
  /** Global streaming state - true if any chat is streaming */
574
651
  isAnyStreaming: boolean;
575
652
  /** Set streaming state for a specific chat instance */
@@ -582,6 +659,12 @@ interface HsafaContextValue extends HsafaConfig {
582
659
  currentChatId?: string;
583
660
  /** Setter for current chat id */
584
661
  setCurrentChatId: (chatId: string) => void;
662
+ tools: Map<string, HsafaTool>;
663
+ uiComponents: Map<string, React__default.ComponentType<Record<string, unknown>>>;
664
+ registerTool: (name: string, tool: HsafaTool) => () => void;
665
+ unregisterTool: (name: string, tool?: HsafaTool) => void;
666
+ registerUIComponent: (name: string, component: React__default.ComponentType<Record<string, unknown>>) => () => void;
667
+ unregisterUIComponent: (name: string, component?: React__default.ComponentType<Record<string, unknown>>) => void;
585
668
  }
586
669
  /**
587
670
  * Props for the HsafaProvider component
@@ -589,6 +672,8 @@ interface HsafaContextValue extends HsafaConfig {
589
672
  interface HsafaProviderProps extends HsafaConfig {
590
673
  /** Child components that will have access to the Hsafa context */
591
674
  children: React__default.ReactNode;
675
+ tools?: Record<string, HsafaTool>;
676
+ uiComponents?: Record<string, React__default.ComponentType<Record<string, unknown>>>;
592
677
  }
593
678
  /**
594
679
  * Provider component that sets up the Hsafa context for the SDK.
@@ -601,7 +686,7 @@ interface HsafaProviderProps extends HsafaConfig {
601
686
  * </HsafaProvider>
602
687
  * ```
603
688
  */
604
- declare function HsafaProvider({ baseUrl, dir, theme, children }: HsafaProviderProps): react_jsx_runtime.JSX.Element;
689
+ declare function HsafaProvider({ baseUrl, dir, theme, children, tools: initialTools, uiComponents: initialUIComponents }: HsafaProviderProps): react_jsx_runtime.JSX.Element;
605
690
  /**
606
691
  * Hook to access the Hsafa context.
607
692
  * Must be used within a HsafaProvider.
@@ -944,4 +1029,4 @@ type FillResult = {
944
1029
  };
945
1030
  declare function FillActiveInput(value: any, options?: FillInputOptions): Promise<FillResult>;
946
1031
 
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 };
1032
+ 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, useHsafaTools, useMessageEditor };