@bikdotai/bik-component-library 0.0.718-beta.13 → 0.0.718-beta.14
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/cjs/assets/icons/Ai_event_generating.svg.js +1 -0
- package/dist/cjs/components/SearchFilter/components/DatePickerButton.js +1 -1
- package/dist/cjs/components/SearchFilter/components/DateRangeOnlyButton.js +1 -1
- package/dist/cjs/components/analytics-chips-and-dropdowns/AnalyticsDropdown.d.ts +1 -3
- package/dist/cjs/components/analytics-chips-and-dropdowns/AnalyticsDropdown.js +1 -1
- package/dist/cjs/components/analytics-chips-and-dropdowns/AnalyticsTrend.d.ts +1 -2
- package/dist/cjs/components/analytics-chips-and-dropdowns/AnalyticsTrend.js +1 -1
- package/dist/cjs/components/analytics-chips-and-dropdowns/CommonStyles.js +1 -1
- package/dist/cjs/components/analytics-chips-and-dropdowns/chart/StackedBarChart/StackedBarChart.js +1 -1
- package/dist/cjs/components/analytics-chips-and-dropdowns/chart/StackedBarChart/StackedBarChart.model.d.ts +4 -1
- package/dist/cjs/components/analytics-chips-and-dropdowns/chart/VerticalBarAndLinearGraph/VerticalBarAndLinearGraph.js +1 -1
- package/dist/cjs/components/analytics-chips-and-dropdowns/chart/VerticalBarAndLinearGraph/VerticalBarAndLinearGraphModel.d.ts +3 -0
- package/dist/cjs/components/analytics-chips-and-dropdowns/chart/heatmap/HeatMap.d.ts +1 -0
- package/dist/cjs/components/analytics-chips-and-dropdowns/chart/heatmap/HeatMap.js +1 -1
- package/dist/cjs/components/analytics-chips-and-dropdowns/chart/heatmap/HeatMapStyled.d.ts +26 -0
- package/dist/cjs/components/analytics-chips-and-dropdowns/chart/heatmap/HeatMapStyled.js +1 -1
- package/dist/cjs/components/analytics-chips-and-dropdowns/chart/heatmap/HeatMapVertical.js +1 -1
- package/dist/cjs/components/bik-chatbot/components/AIChat.d.ts +5 -0
- package/dist/cjs/components/bik-chatbot/components/AIChat.js +1 -0
- package/dist/cjs/components/bik-chatbot/components/BIKChatbot.d.ts +36 -0
- package/dist/cjs/components/bik-chatbot/components/BIKChatbot.js +1 -0
- package/dist/cjs/components/bik-chatbot/components/ChatLoadingState.d.ts +7 -0
- package/dist/cjs/components/bik-chatbot/components/ChatLoadingState.js +177 -0
- package/dist/cjs/components/bik-chatbot/components/ChatWindow.d.ts +12 -0
- package/dist/cjs/components/bik-chatbot/components/ChatWindow.js +252 -0
- package/dist/cjs/components/bik-chatbot/components/ThinkingIndicator.d.ts +3 -0
- package/dist/cjs/components/bik-chatbot/components/ThinkingIndicator.js +188 -0
- package/dist/cjs/components/bik-chatbot/contexts/AIContext.d.ts +4 -0
- package/dist/cjs/components/bik-chatbot/contexts/AIContext.js +1 -0
- package/dist/cjs/components/bik-chatbot/index.d.ts +137 -0
- package/dist/cjs/components/bik-chatbot/services/aiService.d.ts +30 -0
- package/dist/cjs/components/bik-chatbot/services/aiService.js +1 -0
- package/dist/cjs/components/bik-chatbot/services/callToChatbot.d.ts +6 -0
- package/dist/cjs/components/bik-chatbot/services/callToChatbot.js +1 -0
- package/dist/cjs/components/bik-chatbot/services/db.d.ts +6 -0
- package/dist/cjs/components/bik-chatbot/services/db.js +1 -0
- package/dist/cjs/components/bik-chatbot/services/useAIChat.d.ts +7 -0
- package/dist/cjs/components/bik-chatbot/services/useAIChat.js +1 -0
- package/dist/cjs/components/bik-chatbot/types/ai.d.ts +158 -0
- package/dist/cjs/components/bik-chatbot/types/ai.js +1 -0
- package/dist/cjs/components/bik-chatbot/types/chat.d.ts +34 -0
- package/dist/cjs/components/bik-chatbot/types/chat.js +1 -0
- package/dist/cjs/components/bik-chatbot/types/components.d.ts +130 -0
- package/dist/cjs/components/bik-chatbot/types/index.d.ts +6 -0
- package/dist/cjs/components/bik-chatbot/utils/guardrails.d.ts +6 -0
- package/dist/cjs/components/bik-chatbot/utils/guardrails.js +1 -0
- package/dist/cjs/components/bik-chatbot/utils/markdown.d.ts +1 -0
- package/dist/cjs/components/bik-chatbot/utils/markdown.js +1 -0
- package/dist/cjs/components/bik-chatbot-examples/AnalyticsAdvisor.d.ts +8 -0
- package/dist/cjs/components/bik-chatbot-examples/ContentIdeasDemo.d.ts +12 -0
- package/dist/cjs/components/bik-chatbot-examples/SilentModeDemo.d.ts +17 -0
- package/dist/cjs/components/bik-chatbot-examples/SimpleChatbotDemo.d.ts +17 -0
- package/dist/cjs/components/bik-chatbot-examples/SimpleJsonChatDemo.d.ts +16 -0
- package/dist/cjs/components/bik-chatbot-examples/services/MockRequestExecutor.d.ts +17 -0
- package/dist/cjs/components/bik-chatbot-examples/types.ts/examples.d.ts +61 -0
- package/dist/cjs/components/custom-date-time/DateSelector/DateSelector.js +1 -1
- package/dist/cjs/components/datePicker/DatePicker.d.ts +0 -2
- package/dist/cjs/components/datePicker/DatePicker.js +1 -1
- package/dist/cjs/components/datePicker/DatePicker.styled.d.ts +0 -12
- package/dist/cjs/components/datePicker/DatePicker.styled.js +1 -1
- package/dist/cjs/components/datePicker/index.d.ts +0 -1
- package/dist/cjs/components/dropdown/ChipDropdown.d.ts +1 -0
- package/dist/cjs/components/dropdown/ChipDropdown.js +4 -3
- package/dist/cjs/components/dropdown/Dropdown.d.ts +1 -0
- package/dist/cjs/components/floating-action-button/FloatingActionButton.styles.js +1 -1
- package/dist/cjs/components/tabs/Tabs.js +1 -1
- package/dist/cjs/components/tabs/Tabs.model.d.ts +2 -0
- package/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/index.js +1 -1
- package/dist/esm/assets/icons/Ai_event_generating.svg.js +1 -0
- package/dist/esm/components/SearchFilter/components/DatePickerButton.js +1 -1
- package/dist/esm/components/SearchFilter/components/DateRangeOnlyButton.js +1 -1
- package/dist/esm/components/analytics-chips-and-dropdowns/AnalyticsDropdown.d.ts +1 -3
- package/dist/esm/components/analytics-chips-and-dropdowns/AnalyticsDropdown.js +1 -1
- package/dist/esm/components/analytics-chips-and-dropdowns/AnalyticsTrend.d.ts +1 -2
- package/dist/esm/components/analytics-chips-and-dropdowns/AnalyticsTrend.js +1 -1
- package/dist/esm/components/analytics-chips-and-dropdowns/CommonStyles.js +1 -1
- package/dist/esm/components/analytics-chips-and-dropdowns/chart/StackedBarChart/StackedBarChart.js +1 -1
- package/dist/esm/components/analytics-chips-and-dropdowns/chart/StackedBarChart/StackedBarChart.model.d.ts +4 -1
- package/dist/esm/components/analytics-chips-and-dropdowns/chart/VerticalBarAndLinearGraph/VerticalBarAndLinearGraph.js +1 -1
- package/dist/esm/components/analytics-chips-and-dropdowns/chart/VerticalBarAndLinearGraph/VerticalBarAndLinearGraphModel.d.ts +3 -0
- package/dist/esm/components/analytics-chips-and-dropdowns/chart/heatmap/HeatMap.d.ts +1 -0
- package/dist/esm/components/analytics-chips-and-dropdowns/chart/heatmap/HeatMap.js +1 -1
- package/dist/esm/components/analytics-chips-and-dropdowns/chart/heatmap/HeatMapStyled.d.ts +26 -0
- package/dist/esm/components/analytics-chips-and-dropdowns/chart/heatmap/HeatMapStyled.js +1 -1
- package/dist/esm/components/analytics-chips-and-dropdowns/chart/heatmap/HeatMapVertical.js +1 -1
- package/dist/esm/components/bik-chatbot/components/AIChat.d.ts +5 -0
- package/dist/esm/components/bik-chatbot/components/AIChat.js +1 -0
- package/dist/esm/components/bik-chatbot/components/BIKChatbot.d.ts +36 -0
- package/dist/esm/components/bik-chatbot/components/BIKChatbot.js +1 -0
- package/dist/esm/components/bik-chatbot/components/ChatLoadingState.d.ts +7 -0
- package/dist/esm/components/bik-chatbot/components/ChatLoadingState.js +177 -0
- package/dist/esm/components/bik-chatbot/components/ChatWindow.d.ts +12 -0
- package/dist/esm/components/bik-chatbot/components/ChatWindow.js +252 -0
- package/dist/esm/components/bik-chatbot/components/ThinkingIndicator.d.ts +3 -0
- package/dist/esm/components/bik-chatbot/components/ThinkingIndicator.js +188 -0
- package/dist/esm/components/bik-chatbot/contexts/AIContext.d.ts +4 -0
- package/dist/esm/components/bik-chatbot/contexts/AIContext.js +1 -0
- package/dist/esm/components/bik-chatbot/index.d.ts +137 -0
- package/dist/esm/components/bik-chatbot/services/aiService.d.ts +30 -0
- package/dist/esm/components/bik-chatbot/services/aiService.js +1 -0
- package/dist/esm/components/bik-chatbot/services/callToChatbot.d.ts +6 -0
- package/dist/esm/components/bik-chatbot/services/callToChatbot.js +1 -0
- package/dist/esm/components/bik-chatbot/services/db.d.ts +6 -0
- package/dist/esm/components/bik-chatbot/services/db.js +1 -0
- package/dist/esm/components/bik-chatbot/services/useAIChat.d.ts +7 -0
- package/dist/esm/components/bik-chatbot/services/useAIChat.js +1 -0
- package/dist/esm/components/bik-chatbot/types/ai.d.ts +158 -0
- package/dist/esm/components/bik-chatbot/types/ai.js +1 -0
- package/dist/esm/components/bik-chatbot/types/chat.d.ts +34 -0
- package/dist/esm/components/bik-chatbot/types/chat.js +1 -0
- package/dist/esm/components/bik-chatbot/types/components.d.ts +130 -0
- package/dist/esm/components/bik-chatbot/types/index.d.ts +6 -0
- package/dist/esm/components/bik-chatbot/utils/guardrails.d.ts +6 -0
- package/dist/esm/components/bik-chatbot/utils/guardrails.js +1 -0
- package/dist/esm/components/bik-chatbot/utils/markdown.d.ts +1 -0
- package/dist/esm/components/bik-chatbot/utils/markdown.js +1 -0
- package/dist/esm/components/bik-chatbot-examples/AnalyticsAdvisor.d.ts +8 -0
- package/dist/esm/components/bik-chatbot-examples/ContentIdeasDemo.d.ts +12 -0
- package/dist/esm/components/bik-chatbot-examples/SilentModeDemo.d.ts +17 -0
- package/dist/esm/components/bik-chatbot-examples/SimpleChatbotDemo.d.ts +17 -0
- package/dist/esm/components/bik-chatbot-examples/SimpleJsonChatDemo.d.ts +16 -0
- package/dist/esm/components/bik-chatbot-examples/services/MockRequestExecutor.d.ts +17 -0
- package/dist/esm/components/bik-chatbot-examples/types.ts/examples.d.ts +61 -0
- package/dist/esm/components/custom-date-time/DateSelector/DateSelector.js +1 -1
- package/dist/esm/components/datePicker/DatePicker.d.ts +0 -2
- package/dist/esm/components/datePicker/DatePicker.js +1 -1
- package/dist/esm/components/datePicker/DatePicker.styled.d.ts +0 -12
- package/dist/esm/components/datePicker/DatePicker.styled.js +1 -1
- package/dist/esm/components/datePicker/index.d.ts +0 -1
- package/dist/esm/components/dropdown/ChipDropdown.d.ts +1 -0
- package/dist/esm/components/dropdown/ChipDropdown.js +6 -5
- package/dist/esm/components/dropdown/Dropdown.d.ts +1 -0
- package/dist/esm/components/floating-action-button/FloatingActionButton.styles.js +17 -17
- package/dist/esm/components/tabs/Tabs.js +1 -1
- package/dist/esm/components/tabs/Tabs.model.d.ts +2 -0
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.js +1 -1
- package/package.json +2 -1
- package/dist/cjs/components/datePicker/TimePicker.d.ts +0 -9
- package/dist/cjs/components/datePicker/TimePicker.js +0 -1
- package/dist/esm/components/datePicker/TimePicker.d.ts +0 -9
- package/dist/esm/components/datePicker/TimePicker.js +0 -1
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
export { BIKChatbot, default as default } from './components/BIKChatbot';
|
|
2
|
+
export { AIChat } from './components/AIChat';
|
|
3
|
+
export { AIProvider, useAIContext } from './contexts/AIContext';
|
|
4
|
+
export { useAIChat } from './services/useAIChat';
|
|
5
|
+
export type { ChatMessage, ChatState, IceBreaker, VideoStarter, SessionRecord, FunctionDefinition, ToolCall, GenericAIResponse, CallbackPayload, SystemConfig, PromptConfig, ToolPrompt, ApiRequestExecutor, GenericChatbotProps, BIKChatbotProps, AIChatProps, ChatWindowProps, AIProviderProps, AIContextState, UseAIChatProps, AIServiceConstructorProps, ErrorWithMessage, } from './types';
|
|
6
|
+
export { createSessionRecord, DEFAULT_RESPONSE_FORMAT, DEFAULT_MAX_TOOL_CALLS, DEFAULT_CONVERSATION_ID, CHAT_MESSAGE_ROLES, RESPONSE_FORMATS, } from './types';
|
|
7
|
+
/**
|
|
8
|
+
* BIKChatbot - Generic AI Chatbot Component
|
|
9
|
+
*
|
|
10
|
+
* This component provides a flexible, generic chatbot interface that can be configured
|
|
11
|
+
* for any use case through custom prompts, functions, and response handling.
|
|
12
|
+
*
|
|
13
|
+
* ## Generic Mode (Custom Functions & Built-in Tools)
|
|
14
|
+
*
|
|
15
|
+
* ### Simple Text Chatbot (responseFormat: 'text')
|
|
16
|
+
*
|
|
17
|
+
* ```typescript
|
|
18
|
+
* <BIKChatbot
|
|
19
|
+
* systemPrompt="You are a helpful assistant"
|
|
20
|
+
* responseFormat="text"
|
|
21
|
+
* requestExecutor={myRequestExecutor}
|
|
22
|
+
* baseUrl={myBaseUrl}
|
|
23
|
+
* onMessageReceived={(text) => handleText(text)}
|
|
24
|
+
* />
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* ### Analytics Advisor with Functions (and built-in tools)
|
|
28
|
+
*
|
|
29
|
+
* ```typescript
|
|
30
|
+
* <BIKChatbot
|
|
31
|
+
* systemPrompt="You analyze delivery metrics and suggest improvements. Call getAnalytics() to fetch data, then summarize for the user."
|
|
32
|
+
* responseFormat="json"
|
|
33
|
+
* tools={["web_search_preview"]}
|
|
34
|
+
* requestExecutor={myRequestExecutor}
|
|
35
|
+
* baseUrl={myBaseUrl}
|
|
36
|
+
* functions={[
|
|
37
|
+
* {
|
|
38
|
+
* name: "getAnalytics",
|
|
39
|
+
* description: "Fetch delivery rate and engagement metrics",
|
|
40
|
+
* parameters: { type: "object", properties: {}, required: [] }
|
|
41
|
+
* }
|
|
42
|
+
* ]}
|
|
43
|
+
* functionHandler={async (name, args) => {
|
|
44
|
+
* if (name === "getAnalytics") {
|
|
45
|
+
* return { deliveryRate: 0.75, engagementRate: 0.12 };
|
|
46
|
+
* }
|
|
47
|
+
* }}
|
|
48
|
+
* onMessageReceived={(payload) => {
|
|
49
|
+
* // In json mode, payload is parsed JSON when AI returns JSON text
|
|
50
|
+
* // Or TOOL_CALL/TOOL_RESULT when tools are used
|
|
51
|
+
* }}
|
|
52
|
+
* />
|
|
53
|
+
* ```
|
|
54
|
+
*
|
|
55
|
+
* ### Content Idea Generator (Multi-step Tool Calls)
|
|
56
|
+
*
|
|
57
|
+
* ```typescript
|
|
58
|
+
* <BIKChatbot
|
|
59
|
+
* systemPrompt="Call getTrends() to fetch social media trends. Generate 5 content ideas. Call updateIdeas() to save them. Then summarize for the user."
|
|
60
|
+
* responseFormat="json"
|
|
61
|
+
* functions={[
|
|
62
|
+
* { name: "getTrends", description: "Get latest social media trends", parameters: { type: "object", properties: {}, required: [] } },
|
|
63
|
+
* { name: "updateIdeas", description: "Save content ideas", parameters: { type: "object", properties: { ideas: { type: "array", items: { type: "string" } } }, required: ["ideas"] } }
|
|
64
|
+
* ]}
|
|
65
|
+
* functionHandler={async (name, args) => {
|
|
66
|
+
* if (name === "getTrends") return "AI, short-form video, nostalgia marketing";
|
|
67
|
+
* if (name === "updateIdeas") { saveToDatabase(args.ideas); return { success: true }; }
|
|
68
|
+
* }}
|
|
69
|
+
* onMessageReceived={(payload) => {
|
|
70
|
+
* // Handle TOOL_CALL/TOOL_RESULT events or parsed JSON, depending on flow
|
|
71
|
+
* }}
|
|
72
|
+
* />
|
|
73
|
+
* ```
|
|
74
|
+
*
|
|
75
|
+
* ### Silent Background Generation
|
|
76
|
+
*
|
|
77
|
+
* ```typescript
|
|
78
|
+
* <BIKChatbot
|
|
79
|
+
* systemPrompt="Generate email templates for the campaign"
|
|
80
|
+
* responseFormat="json"
|
|
81
|
+
* displayInUI={false} // Silent mode - no chat bubbles
|
|
82
|
+
* onMessageReceived={(payload) => {
|
|
83
|
+
* // Receives data (parsed JSON or tool events) without UI display
|
|
84
|
+
* }}
|
|
85
|
+
* />
|
|
86
|
+
* ```
|
|
87
|
+
*
|
|
88
|
+
* ### Built-in Tools & Campaign Flow (Optional)
|
|
89
|
+
*
|
|
90
|
+
* ```typescript
|
|
91
|
+
* <BIKChatbot
|
|
92
|
+
* systemPrompt={campaignSystemPrompt}
|
|
93
|
+
* tools={["web_search_preview"]}
|
|
94
|
+
* requestExecutor={myRequestExecutor}
|
|
95
|
+
* baseUrl={myBaseUrl}
|
|
96
|
+
* functions={[submitCampaignsFunction]}
|
|
97
|
+
* functionHandler={async (name, args) => name === 'submitCampaigns' ? 'submitted' : 'ok'}
|
|
98
|
+
* onMessageReceived={(event) => {
|
|
99
|
+
* if (event && typeof event === 'object' && 'type' in event && (event as any).type === 'TOOL_CALL') {
|
|
100
|
+
* const d = (event as any).data;
|
|
101
|
+
* if (d?.name === 'submitCampaigns' && Array.isArray(d?.args?.campaigns)) {
|
|
102
|
+
* setCampaigns(d.args.campaigns);
|
|
103
|
+
* }
|
|
104
|
+
* }
|
|
105
|
+
* }}
|
|
106
|
+
* />
|
|
107
|
+
* ```
|
|
108
|
+
*
|
|
109
|
+
* ## Universal Pattern for ANY Use Case
|
|
110
|
+
*
|
|
111
|
+
* 1. Define your custom functions (tools AI can call) and built-in tools (e.g., web_search_preview)
|
|
112
|
+
* 2. Set `responseFormat`:
|
|
113
|
+
* - 'text' for normal chat
|
|
114
|
+
* - 'json' to parse assistant JSON and show parsed.response
|
|
115
|
+
* 3. Implement `functionHandler` for your tools
|
|
116
|
+
* 4. Handle final output in `onMessageReceived`:
|
|
117
|
+
* - text string (when responseFormat='text')
|
|
118
|
+
* - parsed JSON object (when responseFormat='json')
|
|
119
|
+
* - TOOL_CALL / TOOL_RESULT events (when tools are used)
|
|
120
|
+
*
|
|
121
|
+
* **The Universal Flow:**
|
|
122
|
+
* ```
|
|
123
|
+
* User input → AI thinking
|
|
124
|
+
* ↓
|
|
125
|
+
* AI calls custom function (getTrends, getAnalytics, etc.)
|
|
126
|
+
* ↓
|
|
127
|
+
* Your functionHandler executes it
|
|
128
|
+
* ↓
|
|
129
|
+
* Result returned to AI
|
|
130
|
+
* ↓
|
|
131
|
+
* AI calls another function (optional, repeat) or returns final reply
|
|
132
|
+
* ↓
|
|
133
|
+
* Component displays response in chat bubble (or stays silent if displayInUI=false)
|
|
134
|
+
* ↓
|
|
135
|
+
* onMessageReceived receives text, parsed JSON, or tool events
|
|
136
|
+
* ```
|
|
137
|
+
*/
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { AIServiceConstructorProps, ChatMessage, FunctionDefinition, SystemConfig } from '../types';
|
|
2
|
+
import { APIAdapter } from '../types/ai';
|
|
3
|
+
import type { ResponseFormat } from '../types/ai';
|
|
4
|
+
export declare class AIService {
|
|
5
|
+
system: SystemConfig;
|
|
6
|
+
dispatchMessage: (m: ChatMessage) => void;
|
|
7
|
+
customFunctions?: FunctionDefinition[];
|
|
8
|
+
functionHandler?: (name: string, args: unknown) => Promise<unknown>;
|
|
9
|
+
onMessageReceived?: (message: string | object) => void;
|
|
10
|
+
displayInUI?: boolean;
|
|
11
|
+
maxToolCalls?: number;
|
|
12
|
+
maxTokens?: number;
|
|
13
|
+
apiAdapter: APIAdapter;
|
|
14
|
+
responseFormat?: ResponseFormat;
|
|
15
|
+
constructor(opts: AIServiceConstructorProps);
|
|
16
|
+
private sanitizeToolOutput;
|
|
17
|
+
private tryParseAssistantJson;
|
|
18
|
+
private dispatchParsedResponses;
|
|
19
|
+
private makeSystemMessage;
|
|
20
|
+
generate(messages: {
|
|
21
|
+
role: string;
|
|
22
|
+
content: string;
|
|
23
|
+
}[], conversationId: string, intent?: string, lastResponseId?: string): Promise<{
|
|
24
|
+
responseId?: string;
|
|
25
|
+
}>;
|
|
26
|
+
/**
|
|
27
|
+
* Recursive tool call engine for all AI interactions
|
|
28
|
+
*/
|
|
29
|
+
private generateWithRecursiveToolCalls;
|
|
30
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{__rest as e,__awaiter as t}from"../../../_virtual/_tslib.js";import{injectSafetyPrompt as s,sanitizeUserInput as i}from"../utils/guardrails.js";import{callToChatbot as a}from"./callToChatbot.js";class n{constructor(e){if(Object.defineProperty(this,"system",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"dispatchMessage",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"customFunctions",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"functionHandler",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"onMessageReceived",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"displayInUI",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"maxToolCalls",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"maxTokens",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"apiAdapter",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"responseFormat",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.system=e.system,this.dispatchMessage=e.dispatchMessage,this.customFunctions=e.customFunctions,this.functionHandler=e.functionHandler,this.onMessageReceived=e.onMessageReceived,this.displayInUI=!1!==e.displayInUI,this.maxToolCalls=e.maxToolCalls||10,this.maxTokens=e.maxTokens,this.apiAdapter=e.apiAdapter,this.responseFormat=e.responseFormat,!this.apiAdapter)throw new Error("Chatbot authentication not configured: RequestExecutor is required")}sanitizeToolOutput(t,s){try{if(null!==s&&"object"==typeof s){const t=s,{success:i}=t,a=e(t,["success"]);return JSON.stringify(a)}return"string"==typeof s?s:String(s)}catch(e){return"string"==typeof s?s:String(s)}}tryParseAssistantJson(e){if(!e)return null;let t=e.trim();t=t.replace(/^```json\s*/i,"").replace(/^```\s*/i,"").replace(/\s*```$/g,"").trim();try{return JSON.parse(t)}catch(s){try{const e=`[${t.replace(/}\s*{/g,"},{")}]`;return JSON.parse(e)}catch(t){return e}}}dispatchParsedResponses(e){if(!this.displayInUI)return;const t=Date.now();e.forEach(((e,s)=>{let i="",a="assistant";if(e&&"object"==typeof e){const t=e;"string"==typeof t.response?i=t.response:"string"==typeof t.content&&(i=t.content),"system"===t.role&&(a="system")}else"string"==typeof e&&(i=e);i&&this.dispatchMessage({id:`m-${t}-${s}`,role:a,content:i,timestamp:t+s})}))}makeSystemMessage(){return{role:"system",content:s(this.system.systemPrompt)}}generate(e,s){let a=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"default",n=arguments.length>3?arguments[3]:void 0;return t(this,void 0,void 0,(function*(){const t=e.map((e=>({role:e.role,text:i(e.content)}))),o=[{role:"system",text:this.makeSystemMessage().content},...t];return this.generateWithRecursiveToolCalls(o,s,a,n)}))}generateWithRecursiveToolCalls(e,s,i,n){var o,r,l,c,d,h,p,u,m,y;return t(this,void 0,void 0,(function*(){const t=e.map((e=>({role:e.role,text:e.text})));let f,g=n,v=0;for(;v<this.maxToolCalls;){let e;v++;try{if(f)e=f,f=void 0;else{let n;if(1===v&&g){const e=[...t].reverse().find((e=>"user"===e.role));e&&(n=[{role:"user",content:e.text}])}e=yield a(t,i,s,this.system.id,this.apiAdapter,g,this.system.functions,this.system.model,n,this.system.tools,this.maxTokens)}}catch(e){return this.displayInUI&&this.dispatchMessage({id:`m-${Date.now()}`,role:"system",content:`AI error: ${String((null==e?void 0:e.message)||e)}`,timestamp:Date.now()}),{}}if(g=e.responseId,!e.toolCall){if(e.assistantText)if("json"===this.responseFormat){const t=null!==(o=e.parsed)&&void 0!==o?o:this.tryParseAssistantJson(e.assistantText);if(null!=t){const e=Array.isArray(t)?t:[t];this.displayInUI&&this.dispatchParsedResponses(e),null===(r=this.onMessageReceived)||void 0===r||r.call(this,t)}else{const t=e.assistantText.trim();this.displayInUI&&t&&this.dispatchMessage({id:`m-${Date.now()}`,role:"assistant",content:t,timestamp:Date.now()}),null===(l=this.onMessageReceived)||void 0===l||l.call(this,e.assistantText)}}else this.displayInUI&&this.dispatchMessage({id:`m-${Date.now()}`,role:"assistant",content:e.assistantText,timestamp:Date.now()}),null===(c=this.onMessageReceived)||void 0===c||c.call(this,e.assistantText);return{responseId:g}}const{name:n,args:b,toolCallId:I,callId:x}=e.toolCall;I&&t.push({role:"assistant",text:"",toolCallId:I,toolName:n,toolArgs:JSON.stringify(b)});try{const e="string"==typeof b?(()=>{try{return JSON.parse(b)}catch(e){return b}})():b;null===(d=this.onMessageReceived)||void 0===d||d.call(this,{type:"TOOL_CALL",data:{name:n,args:e}});const o=yield this.functionHandler(n,e);if(I?t.push({role:"tool",text:JSON.stringify(o),toolCallId:I}):t.push({role:"tool",text:JSON.stringify(o)}),x){const e="object"==typeof o&&null!==o?o:String(o),r=this.sanitizeToolOutput(n,e);try{const t="string"==typeof e?e:JSON.stringify(e);null===(h=this.onMessageReceived)||void 0===h||h.call(this,{type:"TOOL_RESULT",data:{name:n,preview:t.slice(0,1e3)}})}catch(e){}const l=[{type:"function_call_output",call_id:x,output:r}],c=yield a(t,i,s,this.system.id,this.apiAdapter,g,this.system.functions,this.system.model,l,this.system.tools,this.maxTokens);if(g=c.responseId,!c.toolCall){if(c.assistantText)if("json"===this.responseFormat){const e=null!==(p=c.parsed)&&void 0!==p?p:this.tryParseAssistantJson(c.assistantText);if(null!=e){const t=Array.isArray(e)?e:[e];this.displayInUI&&this.dispatchParsedResponses(t),null===(u=this.onMessageReceived)||void 0===u||u.call(this,e)}else this.displayInUI&&this.dispatchMessage({id:`m-${Date.now()}`,role:"assistant",content:c.assistantText,timestamp:Date.now()}),null===(m=this.onMessageReceived)||void 0===m||m.call(this,c.assistantText)}else this.displayInUI&&this.dispatchMessage({id:`m-${Date.now()}`,role:"assistant",content:c.assistantText,timestamp:Date.now()}),null===(y=this.onMessageReceived)||void 0===y||y.call(this,c.assistantText);return{responseId:g}}f=c}else;}catch(e){return this.displayInUI&&this.dispatchMessage({id:`m-${Date.now()}`,role:"system",content:`Tool error: ${String((null==e?void 0:e.message)||e)}`,timestamp:Date.now()}),{responseId:g}}}return this.displayInUI&&this.dispatchMessage({id:`m-${Date.now()}`,role:"system",content:`Maximum tool call iterations (${this.maxToolCalls}) reached.`,timestamp:Date.now()}),{responseId:g}}))}}export{n as AIService};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { FunctionDefinition, GenericAIResponse, ApiRequestExecutor, ChatMessageItem, FunctionCallOutputItem, APIAdapter } from '../types';
|
|
2
|
+
export declare function createExecutorApiAdapter(executor: ApiRequestExecutor, baseUrl: string, endpointPath?: string): APIAdapter;
|
|
3
|
+
export declare function callToChatbot(history: {
|
|
4
|
+
role: string;
|
|
5
|
+
text: string;
|
|
6
|
+
}[], intent: string | undefined, conversationId: string | undefined, systemId: string | undefined, apiAdapter: APIAdapter, previousResponseId?: string, customFunctions?: FunctionDefinition[], model?: string, nextInput?: Array<ChatMessageItem | FunctionCallOutputItem>, builtinTools?: string[], maxTokens?: number): Promise<GenericAIResponse>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{__awaiter as t}from"../../../_virtual/_tslib.js";import{DEFAULT_MODEL as o}from"../types/ai.js";function e(o,e){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"/openaiApiFunctions-callChatbot";return i=>t(this,void 0,void 0,(function*(){var t,s;const{input:l,model:r,maxTokens:a=4e3,previousResponseId:d,customFunctions:u,builtinTools:p}=i,c={input:l,tools:[...(p||[]).map((t=>({type:t}))),...(v=u,v&&0!==v.length?v.map((t=>({type:"function",name:t.name,description:t.description,parameters:t.parameters}))):[])],model:r,max_output_tokens:a,previous_response_id:d};var v;const m=`${e.replace(/\/$/,"")}${n}`,{status:h,data:g,error:f}=yield o.sendData({apiPath:m,apiMethod:"POST",requestBody:c});if(200!==h||!(null==g?void 0:g.success)){const o=(null===(s=null===(t=null==g?void 0:g.errors)||void 0===t?void 0:t[0])||void 0===s?void 0:s.message)||f;throw new Error("Backend error: "+(o?` - ${String(o)}`:""))}return function(t){const o={assistantText:t.assistantText,parsed:t.parsed,lastResponseId:t.lastResponseId,responseId:t.responseId};return t.toolCall&&(o.toolCall={name:t.toolCall.name,args:t.toolCall.args,toolCallId:t.toolCall.id,callId:t.toolCall.call_id}),o}(g.data)}))}function n(e){let n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"default",i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"default-session",s=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"generic",l=arguments.length>4?arguments[4]:void 0,r=arguments.length>5?arguments[5]:void 0,a=arguments.length>6?arguments[6]:void 0,d=arguments.length>7&&void 0!==arguments[7]?arguments[7]:o,u=arguments.length>8?arguments[8]:void 0,p=arguments.length>9?arguments[9]:void 0,c=arguments.length>10?arguments[10]:void 0;return t(this,void 0,void 0,(function*(){if(!l)throw new Error("Chatbot authentication not configured: RequestExecutor is required");const t=u&&u.length>0?u:function(t){return t.map((t=>{let{role:o,text:e}=t;return{role:o,content:e}}))}(e),o={input:t,intent:n,conversationId:i,systemId:s,previousResponseId:r,customFunctions:a,builtinTools:p,model:d,maxTokens:null!=c?c:4e3};return yield l(o)}))}export{n as callToChatbot,e as createExecutorApiAdapter};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { SessionRecord } from '../types';
|
|
2
|
+
/** Save session record to IndexedDB */
|
|
3
|
+
export declare function saveSession(sessionId: string, record: SessionRecord): Promise<void>;
|
|
4
|
+
export declare function loadSession(sessionId: string): Promise<SessionRecord | null>;
|
|
5
|
+
export declare function deleteSession(sessionId: string): Promise<void>;
|
|
6
|
+
export declare function listSessions(): Promise<string[]>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{__awaiter as i}from"../../../_virtual/_tslib.js";import{set as o,get as t}from"idb-keyval";const n="ai-session:";function r(t,r){return i(this,void 0,void 0,(function*(){yield o(`${n}${t}`,r)}))}function u(o){return i(this,void 0,void 0,(function*(){return(yield t(`${n}${o}`))||null}))}export{u as loadSession,r as saveSession};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ChatMessage, SessionRecord, UseAIChatProps } from '../types';
|
|
2
|
+
export declare function useAIChat({ system, conversationId, skipInitialization, customFunctions, functionHandler, responseFormat, onMessageReceived, displayInUI, maxToolCalls, maxTokens, apiAdapter, }: Omit<UseAIChatProps, 'updateUI'>): {
|
|
3
|
+
messages: ChatMessage[];
|
|
4
|
+
conversation: SessionRecord;
|
|
5
|
+
sendMessage: (content: string, intent?: string) => Promise<void>;
|
|
6
|
+
isApiCallInProgress: boolean;
|
|
7
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{__awaiter as s}from"../../../_virtual/_tslib.js";import{useState as e,useEffect as t,useMemo as a}from"react";import{createSessionRecord as n}from"../types/chat.js";import{AIService as o}from"./aiService.js";import{loadSession as i,saveSession as c}from"./db.js";function r(r){var d=this;let{system:l,conversationId:m,skipInitialization:g=!1,customFunctions:p,functionHandler:b,responseFormat:j,onMessageReceived:u,displayInUI:O,maxToolCalls:I,maxTokens:v,apiAdapter:f}=r;const[w,y]=e((()=>n(m))),[h,D]=e([]),[R,A]=e(),[k,x]=e(!1);t((()=>{i(m).then((s=>{var e;s&&(y(s),D(s.messages),A(null===(e=s.metadata)||void 0===e?void 0:e.lastResponseId))}))}),[m]);const C=a((()=>g?null:new o({system:Object.assign(Object.assign({},l),{handleCallback:(s,e)=>{var t;null===(t=l.handleCallback)||void 0===t||t.call(l,s,e)}}),dispatchMessage:s=>{D((e=>[...e,s])),y((e=>{const t=Object.assign(Object.assign({},e),{updatedAt:Date.now(),messages:[...e.messages,s]});return c(t.sessionId,Object.assign(Object.assign({},t),{metadata:Object.assign(Object.assign({},t.metadata||{}),{lastResponseId:R})})),t}))},customFunctions:p,functionHandler:b,responseFormat:j,onMessageReceived:u,displayInUI:O,maxToolCalls:I,maxTokens:v,apiAdapter:f})),[l.id,g,v]);return{messages:h,conversation:w,sendMessage:function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"default";return s(d,void 0,void 0,(function*(){if(!C)return;const s={id:`u-${Date.now()}`,role:"user",content:e,timestamp:Date.now()};D((e=>[...e,s])),y((e=>{const t=Object.assign(Object.assign({},e),{updatedAt:Date.now(),messages:[...e.messages,s]});return c(t.sessionId,Object.assign(Object.assign({},t),{metadata:Object.assign(Object.assign({},t.metadata||{}),{lastResponseId:R})})),t})),x(!0);try{const e=yield C.generate([...h,s].map((s=>({role:s.role,content:s.content}))),m,t,R);(null==e?void 0:e.responseId)&&(A(e.responseId),y((s=>{const t=Object.assign(Object.assign({},s),{metadata:Object.assign(Object.assign({},s.metadata||{}),{lastResponseId:e.responseId})});return c(t.sessionId,t),t})))}catch(s){const e=(null==s?void 0:s.message)||"Something went wrong. Please try again.",t={id:`err-${Date.now()}`,role:"system",content:e,timestamp:Date.now()};D((s=>[...s,t])),y((s=>{const e=Object.assign(Object.assign({},s),{updatedAt:Date.now(),messages:[...s.messages,t]});return c(e.sessionId,Object.assign(Object.assign({},e),{metadata:Object.assign(Object.assign({},e.metadata||{}),{lastResponseId:R})})),e}))}finally{x(!1)}}))},isApiCallInProgress:k}}export{r as useAIChat};
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AI Service Types
|
|
3
|
+
*
|
|
4
|
+
* Types for AI service functionality, function definitions, and responses.
|
|
5
|
+
*/
|
|
6
|
+
export declare const ALLOWED_MODELS: string[];
|
|
7
|
+
export declare const DEFAULT_MODEL = "gpt-4.1-mini";
|
|
8
|
+
export interface FunctionDefinition {
|
|
9
|
+
name: string;
|
|
10
|
+
description: string;
|
|
11
|
+
parameters: {
|
|
12
|
+
type: 'object';
|
|
13
|
+
properties: Record<string, any>;
|
|
14
|
+
required?: string[];
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
export interface ToolCall {
|
|
18
|
+
name: string;
|
|
19
|
+
args: unknown;
|
|
20
|
+
toolCallId?: string;
|
|
21
|
+
callId?: string;
|
|
22
|
+
}
|
|
23
|
+
export type GenericAIResponse = {
|
|
24
|
+
assistantText: string;
|
|
25
|
+
parsed?: unknown;
|
|
26
|
+
toolCall?: ToolCall;
|
|
27
|
+
lastResponseId: string;
|
|
28
|
+
responseId?: string;
|
|
29
|
+
};
|
|
30
|
+
export interface ChatMessageItem {
|
|
31
|
+
role: 'system' | 'user' | 'assistant';
|
|
32
|
+
content: string;
|
|
33
|
+
}
|
|
34
|
+
export interface FunctionCallOutputItem {
|
|
35
|
+
type: 'function_call_output';
|
|
36
|
+
call_id: string;
|
|
37
|
+
output: string | object;
|
|
38
|
+
}
|
|
39
|
+
export type CallbackPayload = {
|
|
40
|
+
type: 'UI_UPDATE';
|
|
41
|
+
data: unknown;
|
|
42
|
+
} | {
|
|
43
|
+
type: 'UI_SIGNAL';
|
|
44
|
+
data: unknown;
|
|
45
|
+
} | {
|
|
46
|
+
type: 'AI_RESPONSE';
|
|
47
|
+
data: {
|
|
48
|
+
text: string;
|
|
49
|
+
responseId?: string;
|
|
50
|
+
timestamp: number;
|
|
51
|
+
};
|
|
52
|
+
} | {
|
|
53
|
+
type: 'TOOL_CALL';
|
|
54
|
+
data: {
|
|
55
|
+
name: string;
|
|
56
|
+
args: unknown;
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
export interface SystemConfig {
|
|
60
|
+
id: string;
|
|
61
|
+
name: string;
|
|
62
|
+
model: string;
|
|
63
|
+
systemPrompt: string;
|
|
64
|
+
functions?: FunctionDefinition[];
|
|
65
|
+
tools?: string[];
|
|
66
|
+
handleCallback?: (payload: CallbackPayload, ctx: {
|
|
67
|
+
dispatchMessage: (m: any) => void;
|
|
68
|
+
updatePageState: (updater: (s: any) => any) => void;
|
|
69
|
+
updateUI?: (signal: any) => void;
|
|
70
|
+
}) => void;
|
|
71
|
+
}
|
|
72
|
+
export interface PromptConfig {
|
|
73
|
+
goal_prompt?: string;
|
|
74
|
+
use_case_prompt?: string;
|
|
75
|
+
response_instructions?: string;
|
|
76
|
+
store_instructions?: string;
|
|
77
|
+
exit_prompt?: string;
|
|
78
|
+
output_prompt?: string;
|
|
79
|
+
custom_prompt?: string;
|
|
80
|
+
extra_content?: {
|
|
81
|
+
contextual_info?: string;
|
|
82
|
+
brand_info?: string;
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
export interface ToolPrompt {
|
|
86
|
+
tool: string;
|
|
87
|
+
whenToUse: string;
|
|
88
|
+
outputFormat?: string;
|
|
89
|
+
}
|
|
90
|
+
export interface ErrorWithMessage {
|
|
91
|
+
message: string;
|
|
92
|
+
}
|
|
93
|
+
export declare const DEFAULT_RESPONSE_FORMAT: 'text' | 'json';
|
|
94
|
+
export declare const DEFAULT_MAX_TOOL_CALLS = 5;
|
|
95
|
+
export declare const RESPONSE_FORMATS: readonly ["text", "json"];
|
|
96
|
+
export declare const BUILTIN_TOOL_TYPES: readonly ["web_search_preview"];
|
|
97
|
+
export type BuiltinToolType = (typeof BUILTIN_TOOL_TYPES)[number];
|
|
98
|
+
export type BackendTool = {
|
|
99
|
+
type: BuiltinToolType;
|
|
100
|
+
} | {
|
|
101
|
+
type: 'function';
|
|
102
|
+
name: string;
|
|
103
|
+
description: string;
|
|
104
|
+
parameters: object;
|
|
105
|
+
} | ({
|
|
106
|
+
type: string;
|
|
107
|
+
} & Record<string, unknown>);
|
|
108
|
+
export interface BackendApiRequest {
|
|
109
|
+
input: Array<ChatMessageItem | FunctionCallOutputItem>;
|
|
110
|
+
tools: BackendTool[];
|
|
111
|
+
model: string;
|
|
112
|
+
max_output_tokens: number;
|
|
113
|
+
previous_response_id?: string;
|
|
114
|
+
}
|
|
115
|
+
export interface BackendApiResponse {
|
|
116
|
+
status: number;
|
|
117
|
+
success: boolean;
|
|
118
|
+
data: {
|
|
119
|
+
assistantText: string;
|
|
120
|
+
parsed: unknown;
|
|
121
|
+
toolCall?: {
|
|
122
|
+
name: string;
|
|
123
|
+
args: object | string;
|
|
124
|
+
id: string;
|
|
125
|
+
call_id?: string;
|
|
126
|
+
};
|
|
127
|
+
responseId: string;
|
|
128
|
+
lastResponseId: string;
|
|
129
|
+
requiresFunctionCall: boolean;
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
export type ResponseFormat = 'text' | 'json';
|
|
133
|
+
export interface ApiRequestExecutor {
|
|
134
|
+
sendData<T>(opts: {
|
|
135
|
+
apiPath: string;
|
|
136
|
+
apiMethod?: 'POST' | 'GET' | 'PUT' | 'PATCH' | 'DELETE';
|
|
137
|
+
requestBody?: unknown;
|
|
138
|
+
requestHeader?: Record<string, string>;
|
|
139
|
+
skipStoreId?: boolean;
|
|
140
|
+
abortController?: AbortController;
|
|
141
|
+
}): Promise<{
|
|
142
|
+
status: number;
|
|
143
|
+
data?: T;
|
|
144
|
+
error?: unknown;
|
|
145
|
+
}>;
|
|
146
|
+
}
|
|
147
|
+
export type APIAdapter = (request: CallToChatbotRequest) => Promise<GenericAIResponse>;
|
|
148
|
+
export type CallToChatbotRequest = {
|
|
149
|
+
input: Array<ChatMessageItem | FunctionCallOutputItem>;
|
|
150
|
+
intent: string;
|
|
151
|
+
conversationId: string;
|
|
152
|
+
systemId: string;
|
|
153
|
+
previousResponseId?: string;
|
|
154
|
+
customFunctions?: FunctionDefinition[];
|
|
155
|
+
builtinTools?: string[];
|
|
156
|
+
model: string;
|
|
157
|
+
maxTokens?: number;
|
|
158
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const t=["gpt-4.1-nano","gpt-4.1-mini"],n="gpt-4.1-mini",i="text",o=5,p=["text","json"];export{t as ALLOWED_MODELS,o as DEFAULT_MAX_TOOL_CALLS,n as DEFAULT_MODEL,i as DEFAULT_RESPONSE_FORMAT,p as RESPONSE_FORMATS};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Core Chat Types
|
|
3
|
+
*
|
|
4
|
+
* Basic types for chat functionality, messages, and conversation state.
|
|
5
|
+
*/
|
|
6
|
+
export interface ChatMessage {
|
|
7
|
+
id: string;
|
|
8
|
+
role: 'user' | 'assistant' | 'system';
|
|
9
|
+
content: string;
|
|
10
|
+
timestamp: number;
|
|
11
|
+
}
|
|
12
|
+
export type ChatState = 'conversation-starter' | 'default' | 'typing' | 'thinking' | 'conversation';
|
|
13
|
+
export interface IceBreaker {
|
|
14
|
+
id: string;
|
|
15
|
+
text: string;
|
|
16
|
+
category?: string;
|
|
17
|
+
}
|
|
18
|
+
export interface VideoStarter {
|
|
19
|
+
title: string;
|
|
20
|
+
description: string;
|
|
21
|
+
onPlay?: () => void;
|
|
22
|
+
}
|
|
23
|
+
export interface SessionRecord {
|
|
24
|
+
sessionId: string;
|
|
25
|
+
createdAt: number;
|
|
26
|
+
updatedAt: number;
|
|
27
|
+
messages: ChatMessage[];
|
|
28
|
+
metadata?: {
|
|
29
|
+
lastResponseId?: string;
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
export declare function createSessionRecord(sessionId: string): SessionRecord;
|
|
33
|
+
export declare const CHAT_MESSAGE_ROLES: readonly ["user", "assistant", "system"];
|
|
34
|
+
export declare const DEFAULT_CONVERSATION_ID = "default-session";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function s(s){return{sessionId:s,createdAt:Date.now(),updatedAt:Date.now(),messages:[],metadata:{}}}const t=["user","assistant","system"],e="default-session";export{t as CHAT_MESSAGE_ROLES,e as DEFAULT_CONVERSATION_ID,s as createSessionRecord};
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
/**
|
|
3
|
+
* Component Props Types
|
|
4
|
+
*
|
|
5
|
+
* Type definitions for all component props in the bik-chatbot system.
|
|
6
|
+
*/
|
|
7
|
+
import { APIAdapter } from './ai';
|
|
8
|
+
import { ApiRequestExecutor, FunctionDefinition, SystemConfig } from './ai';
|
|
9
|
+
import type { ResponseFormat } from './ai';
|
|
10
|
+
import { ChatMessage, ChatState, IceBreaker, VideoStarter } from './chat';
|
|
11
|
+
export interface GenericChatbotProps {
|
|
12
|
+
systemPrompt: string;
|
|
13
|
+
systemId?: string;
|
|
14
|
+
functions?: FunctionDefinition[];
|
|
15
|
+
tools?: string[];
|
|
16
|
+
functionHandler?: (name: string, args: any) => Promise<any>;
|
|
17
|
+
onMessageReceived?: (message: string | object) => void;
|
|
18
|
+
displayInUI?: boolean;
|
|
19
|
+
maxToolCalls?: number;
|
|
20
|
+
maxTokens?: number;
|
|
21
|
+
requestExecutor: ApiRequestExecutor;
|
|
22
|
+
baseUrl: string;
|
|
23
|
+
endpointPath?: string;
|
|
24
|
+
responseFormat?: ResponseFormat;
|
|
25
|
+
responseSchema?: unknown;
|
|
26
|
+
conversationId?: string;
|
|
27
|
+
className?: string;
|
|
28
|
+
height?: string;
|
|
29
|
+
showHeader?: boolean;
|
|
30
|
+
placeholder?: string;
|
|
31
|
+
iceBreakers?: IceBreaker[];
|
|
32
|
+
videoStarter?: VideoStarter;
|
|
33
|
+
onUIUpdate?: (signal: unknown) => void;
|
|
34
|
+
onMessageSent?: (message: string) => void;
|
|
35
|
+
onIceBreakerClick?: (iceBreaker: IceBreaker) => void;
|
|
36
|
+
chatState?: ChatState;
|
|
37
|
+
inputDisabled?: boolean;
|
|
38
|
+
}
|
|
39
|
+
export interface BIKChatbotProps extends GenericChatbotProps {
|
|
40
|
+
/** AI model to use (optional, defaults to gpt-4o-mini) */
|
|
41
|
+
model?: string;
|
|
42
|
+
}
|
|
43
|
+
export interface AIChatProps {
|
|
44
|
+
className?: string;
|
|
45
|
+
style?: React.CSSProperties;
|
|
46
|
+
header?: string;
|
|
47
|
+
showHeader?: boolean;
|
|
48
|
+
placeholder?: string;
|
|
49
|
+
suggestions?: string[];
|
|
50
|
+
disabled?: boolean;
|
|
51
|
+
isThinking?: boolean;
|
|
52
|
+
height?: string;
|
|
53
|
+
iceBreakers?: IceBreaker[];
|
|
54
|
+
videoStarter?: VideoStarter;
|
|
55
|
+
onMessageSent?: (message: string) => void;
|
|
56
|
+
onIceBreakerClick?: (iceBreaker: IceBreaker) => void;
|
|
57
|
+
chatState?: ChatState;
|
|
58
|
+
inputDisabled?: boolean;
|
|
59
|
+
}
|
|
60
|
+
export interface ChatWindowProps {
|
|
61
|
+
messages: ChatMessage[];
|
|
62
|
+
onSend: (content: string) => void;
|
|
63
|
+
header?: string;
|
|
64
|
+
placeholder?: string;
|
|
65
|
+
suggestions?: string[];
|
|
66
|
+
iceBreakers?: IceBreaker[];
|
|
67
|
+
videoStarter?: VideoStarter;
|
|
68
|
+
disabled?: boolean;
|
|
69
|
+
isThinking?: boolean;
|
|
70
|
+
onIceBreakerClick?: (iceBreaker: IceBreaker) => void;
|
|
71
|
+
chatState?: ChatState;
|
|
72
|
+
inputDisabled?: boolean;
|
|
73
|
+
}
|
|
74
|
+
export interface AIProviderProps {
|
|
75
|
+
children: React.ReactNode;
|
|
76
|
+
systemPrompt: string;
|
|
77
|
+
systemId?: string;
|
|
78
|
+
functions?: FunctionDefinition[];
|
|
79
|
+
tools?: string[];
|
|
80
|
+
functionHandler?: (name: string, args: any) => Promise<any>;
|
|
81
|
+
onMessageReceived?: (message: string | object) => void;
|
|
82
|
+
displayInUI?: boolean;
|
|
83
|
+
maxToolCalls?: number;
|
|
84
|
+
maxTokens?: number;
|
|
85
|
+
requestExecutor: ApiRequestExecutor;
|
|
86
|
+
baseUrl: string;
|
|
87
|
+
endpointPath?: string;
|
|
88
|
+
responseFormat?: ResponseFormat;
|
|
89
|
+
responseSchema?: unknown;
|
|
90
|
+
conversationId?: string;
|
|
91
|
+
onUIUpdate?: (signal: unknown) => void;
|
|
92
|
+
customModel?: string;
|
|
93
|
+
onSystemReady?: (system: SystemConfig) => void;
|
|
94
|
+
}
|
|
95
|
+
export interface AIContextState {
|
|
96
|
+
isReady: boolean;
|
|
97
|
+
isLoading: boolean;
|
|
98
|
+
isApiCallInProgress: boolean;
|
|
99
|
+
system: SystemConfig | null;
|
|
100
|
+
messages: ChatMessage[];
|
|
101
|
+
conversation: unknown;
|
|
102
|
+
sendMessage: (content: string, intent?: string) => Promise<void>;
|
|
103
|
+
error: string | null;
|
|
104
|
+
}
|
|
105
|
+
export interface UseAIChatProps {
|
|
106
|
+
system: SystemConfig;
|
|
107
|
+
conversationId: string;
|
|
108
|
+
updateUI?: (signal: unknown) => void;
|
|
109
|
+
skipInitialization?: boolean;
|
|
110
|
+
customFunctions?: FunctionDefinition[];
|
|
111
|
+
functionHandler?: (name: string, args: any) => Promise<any>;
|
|
112
|
+
onMessageReceived?: (message: string | object) => void;
|
|
113
|
+
displayInUI?: boolean;
|
|
114
|
+
maxToolCalls?: number;
|
|
115
|
+
maxTokens?: number;
|
|
116
|
+
apiAdapter: APIAdapter;
|
|
117
|
+
responseFormat?: ResponseFormat;
|
|
118
|
+
}
|
|
119
|
+
export interface AIServiceConstructorProps {
|
|
120
|
+
system: SystemConfig;
|
|
121
|
+
dispatchMessage: (m: ChatMessage) => void;
|
|
122
|
+
customFunctions?: FunctionDefinition[];
|
|
123
|
+
functionHandler?: (name: string, args: any) => Promise<any>;
|
|
124
|
+
onMessageReceived?: (message: string | object) => void;
|
|
125
|
+
displayInUI?: boolean;
|
|
126
|
+
maxToolCalls?: number;
|
|
127
|
+
maxTokens?: number;
|
|
128
|
+
apiAdapter: APIAdapter;
|
|
129
|
+
responseFormat?: 'text' | 'json';
|
|
130
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare function sanitizeUserInput(text: string): string;
|
|
2
|
+
export declare function injectSafetyPrompt(prompt: string): string;
|
|
3
|
+
export declare function validateOutput(msg: unknown): boolean;
|
|
4
|
+
export declare function validateFunctionCall(fnCall: unknown, allowedFunctions?: Array<{
|
|
5
|
+
name: string;
|
|
6
|
+
}>): boolean;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function o(o){return o?o.replace(/[\u0000-\u001F\u007F]/g,"").trim():""}function n(o){return`${o}\n\nFollow company safety rules: do not provide PII, do not encourage illegal activity, avoid disallowed content.`}export{n as injectSafetyPrompt,o as sanitizeUserInput};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function renderMarkdownLite(text: string): string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function e(e){if(!e)return"";let r=e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">");return r=r.replace(/```([\s\S]*?)```/g,((e,r)=>`<pre><code>${r.replace(/\n/g,"\n")}</code></pre>`)),r=r.replace(/^####\s+(.+)$/gm,"<h4>$1</h4>"),r=r.replace(/^###\s+(.+)$/gm,"<h3>$1</h3>"),r=r.replace(/^##\s+(.+)$/gm,"<h2>$1</h2>"),r=r.replace(/^#\s+(.+)$/gm,"<h1>$1</h1>"),r=r.replace(/\*\*(.+?)\*\*/g,"<strong>$1</strong>"),r=r.replace(/(^|\s)\*(.+?)\*(?=\s|$)/g,"$1<em>$2</em>"),r=r.replace(/(^|\s)_(.+?)_(?=\s|$)/g,"$1<em>$2</em>"),r=r.replace(/\n\n/g,"<br/><br/>"),r=r.replace(/\n/g,"<br/>"),r}export{e as renderMarkdownLite};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Content Ideas Demo - Multi-step tool flow
|
|
3
|
+
* getTrends() -> generate 5 ideas -> updateIdeas({ ideas }) -> final JSON reply
|
|
4
|
+
*/
|
|
5
|
+
import React from 'react';
|
|
6
|
+
export interface ContentIdeasDemoProps {
|
|
7
|
+
height?: string;
|
|
8
|
+
className?: string;
|
|
9
|
+
conversationId?: string;
|
|
10
|
+
}
|
|
11
|
+
export declare const ContentIdeasDemo: React.FC<ContentIdeasDemoProps>;
|
|
12
|
+
export default ContentIdeasDemo;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Silent Function Calls Demo - Testing that custom function calls don't show in chat
|
|
3
|
+
*
|
|
4
|
+
* This demonstrates:
|
|
5
|
+
* - Function calls execute silently (no chat bubbles for function execution)
|
|
6
|
+
* - Only final JSON data is displayed (not in chat)
|
|
7
|
+
* - Follows workflow: User Input → Function Call (SILENT) → Handler → Display Data
|
|
8
|
+
* - Perfect for testing the silent function call behavior
|
|
9
|
+
*/
|
|
10
|
+
import React from 'react';
|
|
11
|
+
export interface SilentModeDemoProps {
|
|
12
|
+
height?: string;
|
|
13
|
+
className?: string;
|
|
14
|
+
conversationId?: string;
|
|
15
|
+
}
|
|
16
|
+
export declare const SilentModeDemo: React.FC<SilentModeDemoProps>;
|
|
17
|
+
export default SilentModeDemo;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Simple Chatbot Demo - Basic text conversation without functions
|
|
3
|
+
*
|
|
4
|
+
* This demonstrates:
|
|
5
|
+
* - Plain text chatbot
|
|
6
|
+
* - No functions or structured data
|
|
7
|
+
* - Basic AI interaction
|
|
8
|
+
* - Web search capability (via Responses API)
|
|
9
|
+
*/
|
|
10
|
+
import React from 'react';
|
|
11
|
+
export interface SimpleChatbotDemoProps {
|
|
12
|
+
height?: string;
|
|
13
|
+
className?: string;
|
|
14
|
+
conversationId?: string;
|
|
15
|
+
}
|
|
16
|
+
export declare const SimpleChatbotDemo: React.FC<SimpleChatbotDemoProps>;
|
|
17
|
+
export default SimpleChatbotDemo;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Simple JSON Chatbot Demo - Assistant returns JSON in text
|
|
3
|
+
*
|
|
4
|
+
* This demonstrates:
|
|
5
|
+
* - responseFormat='json' behavior
|
|
6
|
+
* - Chat bubble shows parsed.response
|
|
7
|
+
* - onMessageReceived receives full parsed JSON
|
|
8
|
+
*/
|
|
9
|
+
import React from 'react';
|
|
10
|
+
export interface SimpleJsonChatbotDemoProps {
|
|
11
|
+
height?: string;
|
|
12
|
+
className?: string;
|
|
13
|
+
conversationId?: string;
|
|
14
|
+
}
|
|
15
|
+
export declare const SimpleJsonChatbotDemo: React.FC<SimpleJsonChatbotDemoProps>;
|
|
16
|
+
export default SimpleJsonChatbotDemo;
|