@hsafa/ui-sdk 0.5.4 → 0.6.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.cjs +8 -15
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +110 -17
- package/dist/index.d.ts +110 -17
- package/dist/index.js +8 -15
- package/dist/index.js.map +1 -1
- package/docs/XMARKDOWN_USAGE.md +196 -0
- package/package.json +20 -19
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
|
/**
|
|
@@ -110,7 +110,7 @@ type AssistantContentPart = {
|
|
|
110
110
|
type: 'tool-call';
|
|
111
111
|
toolCallId: string;
|
|
112
112
|
toolName?: string;
|
|
113
|
-
input?:
|
|
113
|
+
input?: unknown;
|
|
114
114
|
};
|
|
115
115
|
type ChatMessage = {
|
|
116
116
|
id: string;
|
|
@@ -123,23 +123,31 @@ type ChatMessage = {
|
|
|
123
123
|
id: string;
|
|
124
124
|
role: 'assistant';
|
|
125
125
|
content?: string | AssistantContentPart[];
|
|
126
|
-
items:
|
|
126
|
+
items: unknown[];
|
|
127
127
|
reasoning?: string;
|
|
128
128
|
reasoningOpen?: boolean;
|
|
129
|
-
mainAgentActions?:
|
|
129
|
+
mainAgentActions?: unknown[];
|
|
130
130
|
createdAt?: number;
|
|
131
131
|
};
|
|
132
|
-
type HsafaTool = ((input:
|
|
133
|
-
tool: (input:
|
|
132
|
+
type HsafaTool = ((input: unknown) => unknown | Promise<unknown>) | {
|
|
133
|
+
tool: (input: unknown) => unknown | Promise<unknown>;
|
|
134
134
|
executeEachToken?: boolean;
|
|
135
|
+
inputting_start?: (input: unknown, ctx: {
|
|
136
|
+
toolCallId: string;
|
|
137
|
+
toolName: string;
|
|
138
|
+
}) => void;
|
|
139
|
+
running_start?: (input: unknown, ctx: {
|
|
140
|
+
toolCallId: string;
|
|
141
|
+
toolName: string;
|
|
142
|
+
}) => void;
|
|
135
143
|
};
|
|
136
144
|
type CustomToolUIRenderProps = {
|
|
137
145
|
toolName: string;
|
|
138
146
|
toolCallId: string;
|
|
139
|
-
input:
|
|
140
|
-
output:
|
|
147
|
+
input: unknown;
|
|
148
|
+
output: unknown;
|
|
141
149
|
status?: string;
|
|
142
|
-
addToolResult: (result:
|
|
150
|
+
addToolResult: (result: unknown) => void;
|
|
143
151
|
};
|
|
144
152
|
interface HsafaChatProps {
|
|
145
153
|
agentId: string;
|
|
@@ -291,7 +299,7 @@ interface HsafaAgentAPI {
|
|
|
291
299
|
/** Set messages directly (for loading history) */
|
|
292
300
|
setMessages: (messages: any[]) => void;
|
|
293
301
|
/** Notify that messages have changed (for edit operations) */
|
|
294
|
-
notifyMessagesChange: () => void;
|
|
302
|
+
notifyMessagesChange: (messagesOverride?: unknown[], chatIdOverride?: string) => void;
|
|
295
303
|
/** Direct access to the underlying chat API */
|
|
296
304
|
chatApi: any;
|
|
297
305
|
/** Current chat ID */
|
|
@@ -520,10 +528,87 @@ interface MessageEditorAPI {
|
|
|
520
528
|
}
|
|
521
529
|
declare function useMessageEditor(config: UseMessageEditorConfig): MessageEditorAPI;
|
|
522
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
|
+
|
|
523
608
|
/**
|
|
524
609
|
* Handler function for custom actions that can be triggered by the AI agent
|
|
525
610
|
*/
|
|
526
|
-
type HsafaActionHandler = (params:
|
|
611
|
+
type HsafaActionHandler = (params: unknown, meta: {
|
|
527
612
|
/** Name of the action being called */
|
|
528
613
|
name: string;
|
|
529
614
|
/** When the action is being triggered */
|
|
@@ -534,7 +619,7 @@ type HsafaActionHandler = (params: any, meta: {
|
|
|
534
619
|
assistantMessageId?: string;
|
|
535
620
|
/** ID of the current chat session */
|
|
536
621
|
chatId?: string;
|
|
537
|
-
}) => Promise<
|
|
622
|
+
}) => Promise<unknown> | unknown;
|
|
538
623
|
/**
|
|
539
624
|
* Configuration options for the Hsafa SDK
|
|
540
625
|
*/
|
|
@@ -553,15 +638,15 @@ interface HsafaContextValue extends HsafaConfig {
|
|
|
553
638
|
/** Registered custom actions */
|
|
554
639
|
actions: Map<string, HsafaActionHandler>;
|
|
555
640
|
/** Registered custom components */
|
|
556
|
-
components: Map<string, React__default.ComponentType<
|
|
641
|
+
components: Map<string, React__default.ComponentType<Record<string, unknown>>>;
|
|
557
642
|
/** Register a custom action handler */
|
|
558
643
|
registerAction: (name: string, handler: HsafaActionHandler) => () => void;
|
|
559
644
|
/** Unregister a custom action handler */
|
|
560
645
|
unregisterAction: (name: string, handler?: HsafaActionHandler) => void;
|
|
561
646
|
/** Register a custom component */
|
|
562
|
-
registerComponent: (name: string, component: React__default.ComponentType<
|
|
647
|
+
registerComponent: (name: string, component: React__default.ComponentType<Record<string, unknown>>) => () => void;
|
|
563
648
|
/** Unregister a custom component */
|
|
564
|
-
unregisterComponent: (name: string, component?: React__default.ComponentType<
|
|
649
|
+
unregisterComponent: (name: string, component?: React__default.ComponentType<Record<string, unknown>>) => void;
|
|
565
650
|
/** Global streaming state - true if any chat is streaming */
|
|
566
651
|
isAnyStreaming: boolean;
|
|
567
652
|
/** Set streaming state for a specific chat instance */
|
|
@@ -574,6 +659,12 @@ interface HsafaContextValue extends HsafaConfig {
|
|
|
574
659
|
currentChatId?: string;
|
|
575
660
|
/** Setter for current chat id */
|
|
576
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;
|
|
577
668
|
}
|
|
578
669
|
/**
|
|
579
670
|
* Props for the HsafaProvider component
|
|
@@ -581,6 +672,8 @@ interface HsafaContextValue extends HsafaConfig {
|
|
|
581
672
|
interface HsafaProviderProps extends HsafaConfig {
|
|
582
673
|
/** Child components that will have access to the Hsafa context */
|
|
583
674
|
children: React__default.ReactNode;
|
|
675
|
+
tools?: Record<string, HsafaTool>;
|
|
676
|
+
uiComponents?: Record<string, React__default.ComponentType<Record<string, unknown>>>;
|
|
584
677
|
}
|
|
585
678
|
/**
|
|
586
679
|
* Provider component that sets up the Hsafa context for the SDK.
|
|
@@ -593,7 +686,7 @@ interface HsafaProviderProps extends HsafaConfig {
|
|
|
593
686
|
* </HsafaProvider>
|
|
594
687
|
* ```
|
|
595
688
|
*/
|
|
596
|
-
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;
|
|
597
690
|
/**
|
|
598
691
|
* Hook to access the Hsafa context.
|
|
599
692
|
* Must be used within a HsafaProvider.
|
|
@@ -936,4 +1029,4 @@ type FillResult = {
|
|
|
936
1029
|
};
|
|
937
1030
|
declare function FillActiveInput(value: any, options?: FillInputOptions): Promise<FillResult>;
|
|
938
1031
|
|
|
939
|
-
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
|
/**
|
|
@@ -110,7 +110,7 @@ type AssistantContentPart = {
|
|
|
110
110
|
type: 'tool-call';
|
|
111
111
|
toolCallId: string;
|
|
112
112
|
toolName?: string;
|
|
113
|
-
input?:
|
|
113
|
+
input?: unknown;
|
|
114
114
|
};
|
|
115
115
|
type ChatMessage = {
|
|
116
116
|
id: string;
|
|
@@ -123,23 +123,31 @@ type ChatMessage = {
|
|
|
123
123
|
id: string;
|
|
124
124
|
role: 'assistant';
|
|
125
125
|
content?: string | AssistantContentPart[];
|
|
126
|
-
items:
|
|
126
|
+
items: unknown[];
|
|
127
127
|
reasoning?: string;
|
|
128
128
|
reasoningOpen?: boolean;
|
|
129
|
-
mainAgentActions?:
|
|
129
|
+
mainAgentActions?: unknown[];
|
|
130
130
|
createdAt?: number;
|
|
131
131
|
};
|
|
132
|
-
type HsafaTool = ((input:
|
|
133
|
-
tool: (input:
|
|
132
|
+
type HsafaTool = ((input: unknown) => unknown | Promise<unknown>) | {
|
|
133
|
+
tool: (input: unknown) => unknown | Promise<unknown>;
|
|
134
134
|
executeEachToken?: boolean;
|
|
135
|
+
inputting_start?: (input: unknown, ctx: {
|
|
136
|
+
toolCallId: string;
|
|
137
|
+
toolName: string;
|
|
138
|
+
}) => void;
|
|
139
|
+
running_start?: (input: unknown, ctx: {
|
|
140
|
+
toolCallId: string;
|
|
141
|
+
toolName: string;
|
|
142
|
+
}) => void;
|
|
135
143
|
};
|
|
136
144
|
type CustomToolUIRenderProps = {
|
|
137
145
|
toolName: string;
|
|
138
146
|
toolCallId: string;
|
|
139
|
-
input:
|
|
140
|
-
output:
|
|
147
|
+
input: unknown;
|
|
148
|
+
output: unknown;
|
|
141
149
|
status?: string;
|
|
142
|
-
addToolResult: (result:
|
|
150
|
+
addToolResult: (result: unknown) => void;
|
|
143
151
|
};
|
|
144
152
|
interface HsafaChatProps {
|
|
145
153
|
agentId: string;
|
|
@@ -291,7 +299,7 @@ interface HsafaAgentAPI {
|
|
|
291
299
|
/** Set messages directly (for loading history) */
|
|
292
300
|
setMessages: (messages: any[]) => void;
|
|
293
301
|
/** Notify that messages have changed (for edit operations) */
|
|
294
|
-
notifyMessagesChange: () => void;
|
|
302
|
+
notifyMessagesChange: (messagesOverride?: unknown[], chatIdOverride?: string) => void;
|
|
295
303
|
/** Direct access to the underlying chat API */
|
|
296
304
|
chatApi: any;
|
|
297
305
|
/** Current chat ID */
|
|
@@ -520,10 +528,87 @@ interface MessageEditorAPI {
|
|
|
520
528
|
}
|
|
521
529
|
declare function useMessageEditor(config: UseMessageEditorConfig): MessageEditorAPI;
|
|
522
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
|
+
|
|
523
608
|
/**
|
|
524
609
|
* Handler function for custom actions that can be triggered by the AI agent
|
|
525
610
|
*/
|
|
526
|
-
type HsafaActionHandler = (params:
|
|
611
|
+
type HsafaActionHandler = (params: unknown, meta: {
|
|
527
612
|
/** Name of the action being called */
|
|
528
613
|
name: string;
|
|
529
614
|
/** When the action is being triggered */
|
|
@@ -534,7 +619,7 @@ type HsafaActionHandler = (params: any, meta: {
|
|
|
534
619
|
assistantMessageId?: string;
|
|
535
620
|
/** ID of the current chat session */
|
|
536
621
|
chatId?: string;
|
|
537
|
-
}) => Promise<
|
|
622
|
+
}) => Promise<unknown> | unknown;
|
|
538
623
|
/**
|
|
539
624
|
* Configuration options for the Hsafa SDK
|
|
540
625
|
*/
|
|
@@ -553,15 +638,15 @@ interface HsafaContextValue extends HsafaConfig {
|
|
|
553
638
|
/** Registered custom actions */
|
|
554
639
|
actions: Map<string, HsafaActionHandler>;
|
|
555
640
|
/** Registered custom components */
|
|
556
|
-
components: Map<string, React__default.ComponentType<
|
|
641
|
+
components: Map<string, React__default.ComponentType<Record<string, unknown>>>;
|
|
557
642
|
/** Register a custom action handler */
|
|
558
643
|
registerAction: (name: string, handler: HsafaActionHandler) => () => void;
|
|
559
644
|
/** Unregister a custom action handler */
|
|
560
645
|
unregisterAction: (name: string, handler?: HsafaActionHandler) => void;
|
|
561
646
|
/** Register a custom component */
|
|
562
|
-
registerComponent: (name: string, component: React__default.ComponentType<
|
|
647
|
+
registerComponent: (name: string, component: React__default.ComponentType<Record<string, unknown>>) => () => void;
|
|
563
648
|
/** Unregister a custom component */
|
|
564
|
-
unregisterComponent: (name: string, component?: React__default.ComponentType<
|
|
649
|
+
unregisterComponent: (name: string, component?: React__default.ComponentType<Record<string, unknown>>) => void;
|
|
565
650
|
/** Global streaming state - true if any chat is streaming */
|
|
566
651
|
isAnyStreaming: boolean;
|
|
567
652
|
/** Set streaming state for a specific chat instance */
|
|
@@ -574,6 +659,12 @@ interface HsafaContextValue extends HsafaConfig {
|
|
|
574
659
|
currentChatId?: string;
|
|
575
660
|
/** Setter for current chat id */
|
|
576
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;
|
|
577
668
|
}
|
|
578
669
|
/**
|
|
579
670
|
* Props for the HsafaProvider component
|
|
@@ -581,6 +672,8 @@ interface HsafaContextValue extends HsafaConfig {
|
|
|
581
672
|
interface HsafaProviderProps extends HsafaConfig {
|
|
582
673
|
/** Child components that will have access to the Hsafa context */
|
|
583
674
|
children: React__default.ReactNode;
|
|
675
|
+
tools?: Record<string, HsafaTool>;
|
|
676
|
+
uiComponents?: Record<string, React__default.ComponentType<Record<string, unknown>>>;
|
|
584
677
|
}
|
|
585
678
|
/**
|
|
586
679
|
* Provider component that sets up the Hsafa context for the SDK.
|
|
@@ -593,7 +686,7 @@ interface HsafaProviderProps extends HsafaConfig {
|
|
|
593
686
|
* </HsafaProvider>
|
|
594
687
|
* ```
|
|
595
688
|
*/
|
|
596
|
-
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;
|
|
597
690
|
/**
|
|
598
691
|
* Hook to access the Hsafa context.
|
|
599
692
|
* Must be used within a HsafaProvider.
|
|
@@ -936,4 +1029,4 @@ type FillResult = {
|
|
|
936
1029
|
};
|
|
937
1030
|
declare function FillActiveInput(value: any, options?: FillInputOptions): Promise<FillResult>;
|
|
938
1031
|
|
|
939
|
-
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 };
|