@bikdotai/bik-component-library 0.0.706-beta.1 → 0.0.707--bik-chatbot-v1-beta0.1
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/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 +30 -0
- package/dist/cjs/components/bik-chatbot/components/BIKChatbot.js +1 -0
- package/dist/cjs/components/bik-chatbot/components/ChatWindow.d.ts +12 -0
- package/dist/cjs/components/bik-chatbot/components/ChatWindow.js +295 -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 +27 -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 +171 -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 +122 -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 +7 -0
- package/dist/cjs/components/bik-chatbot-examples/CampaignDemo.d.ts +6 -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 +16 -0
- package/dist/cjs/components/bik-chatbot-examples/types.ts/examples.d.ts +61 -0
- package/dist/cjs/components/bik-layout/BikSidebar.js +1 -1
- package/dist/cjs/components/bik-layout/MockMenus.d.ts +1 -0
- package/dist/cjs/components/template-preview/WhatsApp/ChatBtn.d.ts +0 -1
- package/dist/cjs/components/template-preview/WhatsApp/ChatBtn.js +1 -1
- package/dist/cjs/components/template-preview/WhatsApp/ChatUiV2.d.ts +0 -1
- package/dist/cjs/components/template-preview/WhatsApp/ChatUiV2.js +5 -5
- package/dist/cjs/components/template-preview/WhatsApp/WhatsAppLikePreviewV2.js +5 -15
- package/dist/cjs/components/template-preview/WhatsAppTemplatePreview.js +1 -1
- package/dist/cjs/components/template-preview/helpers/TemplateCreatorHelper.d.ts +0 -1
- package/dist/cjs/components/template-preview/helpers/TemplateCreatorHelper.js +1 -1
- package/dist/cjs/components/template-preview/models/WhatsAppTemplate.d.ts +3 -13
- package/dist/cjs/components/template-preview/models/WhatsAppTemplate.js +1 -1
- package/dist/cjs/components/template-preview/models/WhatsappCarouselTemplate.d.ts +3 -3
- package/dist/cjs/index.d.ts +1 -0
- package/dist/cjs/index.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 +30 -0
- package/dist/esm/components/bik-chatbot/components/BIKChatbot.js +1 -0
- package/dist/esm/components/bik-chatbot/components/ChatWindow.d.ts +12 -0
- package/dist/esm/components/bik-chatbot/components/ChatWindow.js +295 -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 +27 -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 +171 -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 +122 -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 +7 -0
- package/dist/esm/components/bik-chatbot-examples/CampaignDemo.d.ts +6 -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 +16 -0
- package/dist/esm/components/bik-chatbot-examples/types.ts/examples.d.ts +61 -0
- package/dist/esm/components/bik-layout/BikSidebar.js +1 -1
- package/dist/esm/components/bik-layout/MockMenus.d.ts +1 -0
- package/dist/esm/components/template-preview/WhatsApp/ChatBtn.d.ts +0 -1
- package/dist/esm/components/template-preview/WhatsApp/ChatBtn.js +1 -1
- package/dist/esm/components/template-preview/WhatsApp/ChatUiV2.d.ts +0 -1
- package/dist/esm/components/template-preview/WhatsApp/ChatUiV2.js +5 -5
- package/dist/esm/components/template-preview/WhatsApp/WhatsAppLikePreviewV2.js +5 -15
- package/dist/esm/components/template-preview/WhatsAppTemplatePreview.js +1 -1
- package/dist/esm/components/template-preview/helpers/TemplateCreatorHelper.d.ts +0 -1
- package/dist/esm/components/template-preview/helpers/TemplateCreatorHelper.js +1 -1
- package/dist/esm/components/template-preview/models/WhatsAppTemplate.d.ts +3 -13
- package/dist/esm/components/template-preview/models/WhatsAppTemplate.js +1 -1
- package/dist/esm/components/template-preview/models/WhatsappCarouselTemplate.d.ts +3 -3
- package/dist/esm/index.d.ts +1 -0
- package/dist/esm/index.js +1 -1
- package/package.json +6 -2
- package/dist/cjs/assets/icons/phone_round.svg.js +0 -1
- package/dist/esm/assets/icons/phone_round.svg.js +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../../_virtual/_tslib.js"),s=require("../../../node_modules/react/jsx-runtime.js"),t=require("../contexts/AIContext.js"),i=require("./ChatWindow.js");exports.AIChat=r=>{let{className:a,style:n,header:o,showHeader:l=!0,placeholder:c="Ask me anything...",suggestions:d=["Top festivals for marketing","Top events this week?","Top August festivals near you"],disabled:x=!1,isThinking:j=!1,height:m,iceBreakers:u,videoStarter:g,onMessageSent:h,onIceBreakerClick:p,chatState:v,chatWindowHeight:b}=r;const{isReady:y,isLoading:f,messages:k,sendMessage:E,error:O,system:R,isApiCallInProgress:N}=t.useAIContext(),A=o||(null==R?void 0:R.name)||"AI Assistant";return O?s.jsxRuntimeExports.jsx("div",Object.assign({className:`flex items-center justify-center p-6 ${a}`,style:n},{children:s.jsxRuntimeExports.jsxs("div",Object.assign({className:"text-red-500 text-center"},{children:[s.jsxRuntimeExports.jsx("div",Object.assign({className:"text-lg font-semibold mb-2"},{children:"Error"})),s.jsxRuntimeExports.jsx("div",Object.assign({className:"text-sm"},{children:O}))]}))})):y?s.jsxRuntimeExports.jsx("div",Object.assign({className:a,style:Object.assign(Object.assign({},n),{height:m,width:"100%"})},{children:s.jsxRuntimeExports.jsx(i.default,{messages:k,onSend:s=>e.__awaiter(void 0,void 0,void 0,(function*(){try{yield E(s),null==h||h(s)}catch(e){console.error("Failed to send message:",e)}})),header:l?A:void 0,placeholder:c,suggestions:d,iceBreakers:u,videoStarter:g,disabled:x||f,isThinking:j||N,onIceBreakerClick:p,chatState:v,chatWindowHeight:b})})):s.jsxRuntimeExports.jsx("div",Object.assign({className:`flex items-center justify-center p-6 ${a}`,style:n},{children:s.jsxRuntimeExports.jsxs("div",Object.assign({className:"text-gray-500"},{children:[s.jsxRuntimeExports.jsx("div",{className:"animate-spin rounded-full h-8 w-8 border-b-2 border-blue-600 mx-auto mb-2"}),s.jsxRuntimeExports.jsx("div",Object.assign({className:"text-center text-sm"},{children:"Initializing AI..."}))]}))}))};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { FC, CSSProperties } from 'react';
|
|
2
|
+
import { BIKChatbotProps } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* BIKChatbot - Generic AI chatbot component
|
|
5
|
+
*
|
|
6
|
+
* This component provides a flexible, generic chatbot interface that can be configured
|
|
7
|
+
* for any use case through custom prompts, functions, and response handling.
|
|
8
|
+
*
|
|
9
|
+
* Usage Examples:
|
|
10
|
+
*
|
|
11
|
+
* // Simple text chatbot
|
|
12
|
+
* <BIKChatbot
|
|
13
|
+
* systemPrompt="You are a helpful assistant"
|
|
14
|
+
* responseFormat="text"
|
|
15
|
+
* onMessageReceived={(text) => console.log(text)}
|
|
16
|
+
* />
|
|
17
|
+
*
|
|
18
|
+
*/
|
|
19
|
+
/**
|
|
20
|
+
* @prop chatWindowHeight - The height (px or string) for internal chat window/messages area. Default 400px.
|
|
21
|
+
*/
|
|
22
|
+
export interface BIKChatbotWithStyleProps extends BIKChatbotProps {
|
|
23
|
+
width?: string | number;
|
|
24
|
+
maxWidth?: string | number;
|
|
25
|
+
style?: CSSProperties;
|
|
26
|
+
chatWindowHeight?: string | number;
|
|
27
|
+
tools?: string[];
|
|
28
|
+
}
|
|
29
|
+
export declare const BIKChatbot: FC<BIKChatbotWithStyleProps>;
|
|
30
|
+
export default BIKChatbot;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../../node_modules/react/jsx-runtime.js"),t=require("../contexts/AIContext.js"),s=require("./AIChat.js");const r=r=>{let{systemPrompt:o,systemId:a,functions:n,functionHandler:i,onMessageReceived:d,displayInUI:c,maxToolCalls:l,model:h,conversationId:m,className:u,height:x,showHeader:p=!0,placeholder:I,iceBreakers:j,videoStarter:g,onMessageSent:f,onIceBreakerClick:v,chatState:y,requestExecutor:b,baseUrl:E,endpointPath:w,responseFormat:C,responseSchema:S,width:k,maxWidth:P,style:q,chatWindowHeight:H,tools:M}=r;if(!o)throw new Error("systemPrompt is required for generic mode.");return e.jsxRuntimeExports.jsx("div",Object.assign({className:u,style:Object.assign({width:k||void 0,maxWidth:P||480,border:"1px solid #E0E0E0",background:"#fff"},q)},{children:e.jsxRuntimeExports.jsx(t.AIProvider,Object.assign({systemPrompt:o,systemId:a,functions:n,functionHandler:i,responseFormat:C,responseSchema:S,onMessageReceived:d,displayInUI:c,maxToolCalls:l,customModel:h,conversationId:m,requestExecutor:b,baseUrl:E,endpointPath:w,tools:M},{children:e.jsxRuntimeExports.jsx(s.AIChat,{height:x,chatWindowHeight:H,showHeader:p,placeholder:I,iceBreakers:j,videoStarter:g,onMessageSent:f,onIceBreakerClick:v,chatState:y})}))}))};exports.BIKChatbot=r,exports.default=r;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { ChatWindowProps } from '../types';
|
|
3
|
+
export declare const CustomGradientText: import("styled-components").StyledComponent<"span", any, {
|
|
4
|
+
colors?: string | undefined;
|
|
5
|
+
angle?: number | undefined;
|
|
6
|
+
}, never>;
|
|
7
|
+
export type { ChatState } from '../types';
|
|
8
|
+
interface ChatWindowWithHeightProps extends ChatWindowProps {
|
|
9
|
+
chatWindowHeight?: string | number;
|
|
10
|
+
}
|
|
11
|
+
declare const ChatWindow: React.FC<ChatWindowWithHeightProps>;
|
|
12
|
+
export default ChatWindow;
|
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../../node_modules/react/jsx-runtime.js"),t=require("react"),i=require("styled-components"),r=require("../../TypographyStyle.js"),n=require("../utils/markdown.js");function s(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var o=s(i);const a=o.default.div`
|
|
2
|
+
display: flex;
|
|
3
|
+
flex-direction: column;
|
|
4
|
+
width: 100%;
|
|
5
|
+
min-width: 356px;
|
|
6
|
+
min-height: 400px;
|
|
7
|
+
height: 100%;
|
|
8
|
+
background: white;
|
|
9
|
+
border-left: 1px solid #e5e7eb;
|
|
10
|
+
position: relative;
|
|
11
|
+
|
|
12
|
+
/* State-based styling */
|
|
13
|
+
${e=>{switch(e.chatState){case"conversation-starter":return"\n background: linear-gradient(180deg, #FFF6F9 0%, #FFFFFF 100%);\n ";case"thinking":return"\n background: linear-gradient(180deg, #F8F9FA 0%, #FFFFFF 100%);\n ";default:return"\n background: white;\n "}}}
|
|
14
|
+
`,d=o.default.div`
|
|
15
|
+
padding: 16px;
|
|
16
|
+
border-bottom: 1px solid #e5e7eb;
|
|
17
|
+
display: flex;
|
|
18
|
+
align-items: center;
|
|
19
|
+
gap: 8px;
|
|
20
|
+
background: white;
|
|
21
|
+
flex-shrink: 0;
|
|
22
|
+
|
|
23
|
+
.ai-icon {
|
|
24
|
+
width: 16px;
|
|
25
|
+
height: 16px;
|
|
26
|
+
background: linear-gradient(45deg, #ff6b6b, #4ecdc4);
|
|
27
|
+
border-radius: 3px;
|
|
28
|
+
display: flex;
|
|
29
|
+
align-items: center;
|
|
30
|
+
justify-content: center;
|
|
31
|
+
font-size: 8px;
|
|
32
|
+
color: white;
|
|
33
|
+
font-weight: bold;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
.header-text {
|
|
37
|
+
font-size: 14px;
|
|
38
|
+
font-weight: 500;
|
|
39
|
+
color: #374151;
|
|
40
|
+
}
|
|
41
|
+
`,l=o.default.div`
|
|
42
|
+
flex: 1;
|
|
43
|
+
display: flex;
|
|
44
|
+
flex-direction: column;
|
|
45
|
+
overflow: hidden;
|
|
46
|
+
`,x=o.default.div`
|
|
47
|
+
flex: 1;
|
|
48
|
+
overflow-y: auto;
|
|
49
|
+
padding: 16px;
|
|
50
|
+
display: flex;
|
|
51
|
+
flex-direction: column;
|
|
52
|
+
gap: 16px;
|
|
53
|
+
background: #fafafa;
|
|
54
|
+
scroll-behavior: smooth;
|
|
55
|
+
|
|
56
|
+
/* Custom scrollbar */
|
|
57
|
+
&::-webkit-scrollbar {
|
|
58
|
+
width: 6px;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
&::-webkit-scrollbar-track {
|
|
62
|
+
background: #f1f1f1;
|
|
63
|
+
border-radius: 3px;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
&::-webkit-scrollbar-thumb {
|
|
67
|
+
background: #c1c1c1;
|
|
68
|
+
border-radius: 3px;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
&::-webkit-scrollbar-thumb:hover {
|
|
72
|
+
background: #a8a8a8;
|
|
73
|
+
}
|
|
74
|
+
`,p=o.default.div`
|
|
75
|
+
background: white;
|
|
76
|
+
border-radius: 12px;
|
|
77
|
+
padding: 16px;
|
|
78
|
+
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
|
|
79
|
+
border: 1px solid #e5e7eb;
|
|
80
|
+
`,c=o.default.div`
|
|
81
|
+
width: 100%;
|
|
82
|
+
height: 180px;
|
|
83
|
+
background: #f3f4f6;
|
|
84
|
+
border-radius: 8px;
|
|
85
|
+
display: flex;
|
|
86
|
+
align-items: center;
|
|
87
|
+
justify-content: center;
|
|
88
|
+
position: relative;
|
|
89
|
+
margin-bottom: 12px;
|
|
90
|
+
`,u=o.default.div`
|
|
91
|
+
width: 48px;
|
|
92
|
+
height: 48px;
|
|
93
|
+
background: rgba(0, 0, 0, 0.7);
|
|
94
|
+
border-radius: 50%;
|
|
95
|
+
display: flex;
|
|
96
|
+
align-items: center;
|
|
97
|
+
justify-content: center;
|
|
98
|
+
cursor: pointer;
|
|
99
|
+
transition: all 0.2s ease;
|
|
100
|
+
|
|
101
|
+
&:hover {
|
|
102
|
+
background: rgba(0, 0, 0, 0.8);
|
|
103
|
+
transform: scale(1.05);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
svg {
|
|
107
|
+
width: 16px;
|
|
108
|
+
height: 16px;
|
|
109
|
+
fill: white;
|
|
110
|
+
margin-left: 2px;
|
|
111
|
+
}
|
|
112
|
+
`,h=o.default.div`
|
|
113
|
+
font-size: 14px;
|
|
114
|
+
color: #374151;
|
|
115
|
+
line-height: 1.5;
|
|
116
|
+
`,g=o.default.div`
|
|
117
|
+
padding: 12px 16px;
|
|
118
|
+
border-radius: 16px;
|
|
119
|
+
font-size: 14px;
|
|
120
|
+
max-width: 80%;
|
|
121
|
+
white-space: pre-line;
|
|
122
|
+
word-wrap: break-word;
|
|
123
|
+
|
|
124
|
+
${e=>"user"===e.role?"\n background: #3b82f6;\n color: white;\n margin-left: auto;\n border-bottom-right-radius: 4px;\n ":"system"===e.role?"\n background: #f3f4f6;\n color: #6b7280;\n font-size: 12px;\n font-style: italic;\n text-align: center;\n margin: 0 auto;\n max-width: 90%;\n ":"\n background: white;\n color: #111827;\n border: 1px solid #e5e7eb;\n margin-right: auto;\n border-bottom-left-radius: 4px;\n box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);\n "}
|
|
125
|
+
`,b=o.default.div`
|
|
126
|
+
background: white;
|
|
127
|
+
border: 1px solid #e5e7eb;
|
|
128
|
+
padding: 12px 16px;
|
|
129
|
+
border-radius: 16px;
|
|
130
|
+
border-bottom-left-radius: 4px;
|
|
131
|
+
max-width: 80%;
|
|
132
|
+
margin-right: auto;
|
|
133
|
+
font-size: 14px;
|
|
134
|
+
color: #6b7280;
|
|
135
|
+
font-style: italic;
|
|
136
|
+
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
|
|
137
|
+
display: flex;
|
|
138
|
+
align-items: center;
|
|
139
|
+
gap: 8px;
|
|
140
|
+
|
|
141
|
+
.spinner {
|
|
142
|
+
width: 12px;
|
|
143
|
+
height: 12px;
|
|
144
|
+
border: 2px solid #e5e7eb;
|
|
145
|
+
border-top: 2px solid #3b82f6;
|
|
146
|
+
border-radius: 50%;
|
|
147
|
+
animation: spin 1s linear infinite;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
@keyframes spin {
|
|
151
|
+
0% {
|
|
152
|
+
transform: rotate(0deg);
|
|
153
|
+
}
|
|
154
|
+
100% {
|
|
155
|
+
transform: rotate(360deg);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
`,f=o.default.div`
|
|
159
|
+
padding: 16px;
|
|
160
|
+
flex-shrink: 0;
|
|
161
|
+
`,m=o.default.div`
|
|
162
|
+
display: flex;
|
|
163
|
+
flex-direction: column;
|
|
164
|
+
gap: 8px;
|
|
165
|
+
align-items: flex-end;
|
|
166
|
+
`,j=o.default.button`
|
|
167
|
+
border: 1px dotted #febad2;
|
|
168
|
+
background: linear-gradient(
|
|
169
|
+
92.69deg,
|
|
170
|
+
rgba(255, 230, 238, 0.5) 0.37%,
|
|
171
|
+
rgba(255, 240, 231, 0.5) 100%
|
|
172
|
+
);
|
|
173
|
+
padding: 8px 16px;
|
|
174
|
+
border-radius: 8px;
|
|
175
|
+
font-size: 13px;
|
|
176
|
+
cursor: pointer;
|
|
177
|
+
transition: all 0.2s ease;
|
|
178
|
+
text-align: left;
|
|
179
|
+
max-width: 280px;
|
|
180
|
+
align-self: flex-end;
|
|
181
|
+
|
|
182
|
+
&:hover {
|
|
183
|
+
background: linear-gradient(
|
|
184
|
+
92.69deg,
|
|
185
|
+
rgba(255, 230, 238, 0.7) 0.37%,
|
|
186
|
+
rgba(255, 240, 231, 0.7) 100%
|
|
187
|
+
);
|
|
188
|
+
border-color: #f472b6;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
&:active {
|
|
192
|
+
transform: scale(0.98);
|
|
193
|
+
}
|
|
194
|
+
`,w=o.default.div`
|
|
195
|
+
padding: 16px;
|
|
196
|
+
background: white;
|
|
197
|
+
`,v=o.default.div`
|
|
198
|
+
display: flex;
|
|
199
|
+
flex-direction: column;
|
|
200
|
+
gap: 8px;
|
|
201
|
+
`,k=o.default.button`
|
|
202
|
+
background: #fef2f2;
|
|
203
|
+
color: #dc2626;
|
|
204
|
+
padding: 12px 16px;
|
|
205
|
+
border-radius: 8px;
|
|
206
|
+
font-size: 13px;
|
|
207
|
+
border: 1px solid #fecaca;
|
|
208
|
+
cursor: pointer;
|
|
209
|
+
transition: all 0.2s ease;
|
|
210
|
+
text-align: left;
|
|
211
|
+
|
|
212
|
+
&:hover {
|
|
213
|
+
background: #fee2e2;
|
|
214
|
+
border-color: #fca5a5;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
&:active {
|
|
218
|
+
transform: scale(0.98);
|
|
219
|
+
}
|
|
220
|
+
`,y=o.default.div`
|
|
221
|
+
padding: 16px;
|
|
222
|
+
flex-shrink: 0;
|
|
223
|
+
`,E=o.default.div`
|
|
224
|
+
position: relative;
|
|
225
|
+
display: flex;
|
|
226
|
+
width: 100%;
|
|
227
|
+
`,R=o.default.textarea`
|
|
228
|
+
flex: 1;
|
|
229
|
+
border: 1px solid ${e=>e.hasText?"#3b82f6":"#d1d5db"};
|
|
230
|
+
border-radius: 12px;
|
|
231
|
+
padding: 12px;
|
|
232
|
+
padding-right: 48px;
|
|
233
|
+
font-size: 14px;
|
|
234
|
+
outline: none;
|
|
235
|
+
color: #374151;
|
|
236
|
+
background: white;
|
|
237
|
+
box-shadow: 0px 2px 8px 0px #0000001f;
|
|
238
|
+
transition: all 0.2s ease;
|
|
239
|
+
resize: none;
|
|
240
|
+
min-height: 44px;
|
|
241
|
+
max-height: 120px;
|
|
242
|
+
font-family: inherit;
|
|
243
|
+
width: 100%;
|
|
244
|
+
|
|
245
|
+
&:focus {
|
|
246
|
+
border-color: #3b82f6;
|
|
247
|
+
background: white;
|
|
248
|
+
box-shadow: 0px 2px 8px 0px #0000001f, 0 0 0 3px rgba(59, 130, 246, 0.1);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
&::placeholder {
|
|
252
|
+
color: #9ca3af;
|
|
253
|
+
}
|
|
254
|
+
`,F=o.default.button`
|
|
255
|
+
position: absolute;
|
|
256
|
+
bottom: 10px;
|
|
257
|
+
right: 10px;
|
|
258
|
+
width: 36px;
|
|
259
|
+
height: 36px;
|
|
260
|
+
border-radius: 50%;
|
|
261
|
+
background: ${e=>e.hasText?"linear-gradient(135deg, #FF166A 0%, #FB5F08 100%)":"#e5e7eb"};
|
|
262
|
+
border: none;
|
|
263
|
+
display: flex;
|
|
264
|
+
align-items: center;
|
|
265
|
+
justify-content: center;
|
|
266
|
+
cursor: ${e=>e.disabled?"not-allowed":"pointer"};
|
|
267
|
+
transition: all 0.2s ease;
|
|
268
|
+
box-shadow: 0 2px 8px 0px #fa709a1c;
|
|
269
|
+
z-index: 2;
|
|
270
|
+
|
|
271
|
+
&:hover:not(:disabled) {
|
|
272
|
+
background: ${e=>e.hasText?"linear-gradient(135deg, #F857A6 0%, #FF5858 100%)":"#e5e7eb"};
|
|
273
|
+
transform: scale(1.05);
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
&:active:not(:disabled) {
|
|
277
|
+
transform: scale(0.95);
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
svg {
|
|
281
|
+
width: 16px;
|
|
282
|
+
height: 16px;
|
|
283
|
+
fill: white;
|
|
284
|
+
font-weight: bold;
|
|
285
|
+
}
|
|
286
|
+
`,S=o.default.span`
|
|
287
|
+
background: linear-gradient(
|
|
288
|
+
${e=>e.angle||92.69}deg,
|
|
289
|
+
${e=>e.colors||"#ff166a 0.37%, #fb5f08 100%"}
|
|
290
|
+
);
|
|
291
|
+
-webkit-background-clip: text;
|
|
292
|
+
-webkit-text-fill-color: transparent;
|
|
293
|
+
background-clip: text;
|
|
294
|
+
display: inline-block;
|
|
295
|
+
`;exports.CustomGradientText=S,exports.default=i=>{let{messages:s,onSend:o,header:O="Create with AI",placeholder:T="Discover the right event & launch campaigns for better conversions...",suggestions:z=["Top festivals for marketing","Top events this week?","Top August festivals near you"],iceBreakers:C,videoStarter:$,disabled:B=!1,isThinking:M=!1,onIceBreakerClick:A,chatState:q,chatWindowHeight:I}=i;const[_,L]=t.useState(""),[D,H]=t.useState(!1),[N,W]=t.useState(!1),K=t.useRef(null),P=t.useRef(null),G=q||(D||M?"thinking":N&&_.trim().length>0?"typing":0===s.length?"conversation-starter":s.length>0?"conversation":"default"),V=()=>{_.trim()&&!B&&(o(_),L(""),H(!0),setTimeout((()=>H(!1)),1500))},J=_.trim().length>0;return t.useEffect((()=>{var e;null===(e=K.current)||void 0===e||e.scrollIntoView({behavior:"smooth"})}),[s,D]),e.jsxRuntimeExports.jsxs(a,Object.assign({chatState:G,style:{height:I||400}},{children:[e.jsxRuntimeExports.jsxs(d,{children:[e.jsxRuntimeExports.jsx("div",Object.assign({className:"ai-icon"},{children:"✦"})),e.jsxRuntimeExports.jsx("div",Object.assign({className:"header-text"},{children:O}))]}),e.jsxRuntimeExports.jsxs(l,{children:[e.jsxRuntimeExports.jsxs(x,{children:["conversation-starter"===G&&$&&e.jsxRuntimeExports.jsxs(p,{children:[e.jsxRuntimeExports.jsx(c,{children:e.jsxRuntimeExports.jsx(u,Object.assign({onClick:$.onPlay},{children:e.jsxRuntimeExports.jsx("svg",Object.assign({viewBox:"0 0 24 24",fill:"currentColor"},{children:e.jsxRuntimeExports.jsx("path",{d:"M8 5v14l11-7z"})}))}))}),e.jsxRuntimeExports.jsxs(h,{children:[e.jsxRuntimeExports.jsx(r.BodySecondary,Object.assign({style:{fontWeight:500,marginBottom:"4px"}},{children:$.title})),e.jsxRuntimeExports.jsx(r.BodyCaption,{children:$.description})]})]}),s.map((t=>e.jsxRuntimeExports.jsx(g,Object.assign({role:t.role},{children:"assistant"===t.role?e.jsxRuntimeExports.jsx("div",{dangerouslySetInnerHTML:{__html:n.renderMarkdownLite(t.content)}}):e.jsxRuntimeExports.jsx("div",Object.assign({style:{whiteSpace:"pre-wrap"}},{children:t.content}))}),t.id))),(D||M)&&e.jsxRuntimeExports.jsxs(b,{children:[e.jsxRuntimeExports.jsx("div",{className:"spinner"}),"AI is thinking..."]}),e.jsxRuntimeExports.jsx("div",{ref:K})]}),C&&"conversation-starter"===G&&e.jsxRuntimeExports.jsx(f,{children:e.jsxRuntimeExports.jsx(m,{children:C.map((t=>e.jsxRuntimeExports.jsx(j,Object.assign({onClick:()=>{B||(null==A||A(t),o(t.text))}},{children:e.jsxRuntimeExports.jsx(S,{children:t.text})}),t.id)))})}),!C&&z.length>0&&"default"===G&&e.jsxRuntimeExports.jsx(w,{children:e.jsxRuntimeExports.jsx(v,{children:z.map((t=>e.jsxRuntimeExports.jsx(k,Object.assign({onClick:()=>!B&&o(t)},{children:t}),t)))})}),e.jsxRuntimeExports.jsx(y,{children:e.jsxRuntimeExports.jsxs(E,{children:[e.jsxRuntimeExports.jsx(R,{ref:P,value:_,onChange:e=>{const t=e.target.value;L(t),W(t.trim().length>0);const i=P.current;i&&(i.style.height="auto",i.style.height=`${Math.min(i.scrollHeight,117)}px`)},placeholder:T,onKeyDown:e=>{"Enter"!==e.key||e.shiftKey||(e.preventDefault(),V())},disabled:B,hasText:J,chatState:G}),e.jsxRuntimeExports.jsx(F,Object.assign({onClick:V,disabled:B||!J,hasText:J,"aria-label":"Send"},{children:e.jsxRuntimeExports.jsxs("svg",Object.assign({viewBox:"0 0 24 24",width:"20",height:"20",stroke:"white",strokeWidth:"2",fill:"none",strokeLinecap:"round",strokeLinejoin:"round"},{children:[e.jsxRuntimeExports.jsx("path",{d:"M6 12h12"}),e.jsxRuntimeExports.jsx("path",{d:"M12 6l6 6-6 6"})]}))}))]})})]})]}))};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../../_virtual/_tslib.js"),s=require("../../../node_modules/react/jsx-runtime.js"),t=require("react"),o=require("../services/useAIChat.js"),r=require("../services/callToChatbot.js");const n=t.createContext(null);exports.AIProvider=i=>{let{children:a,systemPrompt:u,systemId:c,functions:l,tools:d,functionHandler:m,onMessageReceived:p,displayInUI:v,maxToolCalls:g,requestExecutor:I,baseUrl:f,endpointPath:x,responseFormat:A,conversationId:y="default-session",customModel:h}=i;const[C,q]=t.useState(null),[P,b]=t.useState(!0),[E,j]=t.useState(null);t.useEffect((()=>u?I&&f?void j(null):(j("Chatbot authentication not configured: RequestExecutor and baseUrl are required"),void b(!1)):(j("systemPrompt is required for generic mode"),void b(!1))),[u,I,f]);const _=t.useCallback((()=>e.__awaiter(void 0,void 0,void 0,(function*(){try{b(!0),j(null);q({id:c||"generic",name:c?`${c} AI Assistant`:"Generic AI Assistant",model:h||"gpt-4o-mini",systemPrompt:u,functions:l,tools:d})}catch(e){console.error("Error creating system:",e),j("Failed to create AI system")}finally{b(!1)}}))),[h,u,c,l]);t.useEffect((()=>{u&&_()}),[_]);const{messages:w,conversation:M,sendMessage:R,isApiCallInProgress:F}=o.useAIChat({system:C||{id:"loading",name:"Loading...",model:"gpt-4o-mini",systemPrompt:"Loading...",functions:[]},conversationId:y,skipInitialization:!C,customFunctions:l,functionHandler:m,responseFormat:A,onMessageReceived:p,displayInUI:v,maxToolCalls:g,apiAdapter:I&&f?r.createExecutorApiAdapter(I,f,x||void 0):()=>{throw new Error("Chatbot authentication not configured: RequestExecutor is required")}}),U={isReady:!!C&&!P,isLoading:P,isApiCallInProgress:F,system:C,messages:w,conversation:M,sendMessage:R,error:E};return s.jsxRuntimeExports.jsx(n.Provider,Object.assign({value:U},{children:a}))},exports.useAIContext=()=>{const e=t.useContext(n);if(!e)throw new Error("useAIContext must be used within an AIProvider");return e};
|
|
@@ -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, ModelTier, FunctionDefinition, ToolCall, ResponseToolCall, GenericAIResponse, CallbackPayload, SystemConfig, PromptConfig, ToolPrompt, ApiRequestExecutor, GenericChatbotProps, BIKChatbotProps, AIChatProps, ChatWindowProps, AIProviderProps, AIContextState, UseAIChatProps, AIServiceConstructorProps, ErrorWithMessage, } from './types';
|
|
6
|
+
export { createSessionRecord, DEFAULT_MODEL, 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) => console.log(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,27 @@
|
|
|
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
|
+
apiAdapter: APIAdapter;
|
|
13
|
+
responseFormat?: ResponseFormat;
|
|
14
|
+
constructor(opts: AIServiceConstructorProps);
|
|
15
|
+
private sanitizeToolOutput;
|
|
16
|
+
private makeSystemMessage;
|
|
17
|
+
generate(messages: {
|
|
18
|
+
role: string;
|
|
19
|
+
content: string;
|
|
20
|
+
}[], conversationId: string, intent?: string, lastResponseId?: string): Promise<{
|
|
21
|
+
responseId?: string;
|
|
22
|
+
}>;
|
|
23
|
+
/**
|
|
24
|
+
* Recursive tool call engine for all AI interactions
|
|
25
|
+
*/
|
|
26
|
+
private generateWithRecursiveToolCalls;
|
|
27
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../../_virtual/_tslib.js"),t=require("../utils/guardrails.js"),s=require("./callToChatbot.js");exports.AIService=class{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,"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.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,o=e.__rest(t,["success"]);return JSON.stringify(o)}return"string"==typeof s?s:String(s)}catch(e){return String(s)}}makeSystemMessage(){return{role:"system",content:t.injectSafetyPrompt(this.system.systemPrompt)}}generate(s,i){let o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"default",a=arguments.length>3?arguments[3]:void 0;return e.__awaiter(this,void 0,void 0,(function*(){const e=s.map((e=>({role:e.role,text:t.sanitizeUserInput(e.content)}))),n=[{role:"system",text:this.makeSystemMessage().content},...e];return this.generateWithRecursiveToolCalls(n,i,o,a)}))}generateWithRecursiveToolCalls(t,i,o,a){var n,l,r,c,d,h,u,p;return e.__awaiter(this,void 0,void 0,(function*(){const e=t.map((e=>({role:e.role,text:e.text})));let m=a,y=0;const g=[];let f;for(;y<this.maxToolCalls;){let t;y++,console.log(`🔄 Recursive tool call iteration ${y}/${this.maxToolCalls}`);try{if(f)t=f,f=void 0;else{let a;if(1===y&&m){const t=[...e].reverse().find((e=>"user"===e.role));t&&(a=[{role:"user",content:t.text}])}t=yield s.callToChatbot(e,o,i,this.system.id,this.apiAdapter,m,this.system.functions,this.system.model,a,this.system.tools)}}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(m=t.responseId,!t.toolCall){if(console.log(`✅ Completed after ${y} iterations. Tool calls made:`,g.map((e=>e.name)).join(", ")||"none"),t.assistantText)if("json"===this.responseFormat)try{const e=JSON.parse(t.assistantText);if(this.displayInUI){const s="string"==typeof(null==e?void 0:e.response)?e.response:t.assistantText;this.dispatchMessage({id:`m-${Date.now()}`,role:"assistant",content:s,timestamp:Date.now()})}null===(n=this.onMessageReceived)||void 0===n||n.call(this,e)}catch(e){this.displayInUI&&this.dispatchMessage({id:`m-${Date.now()}`,role:"assistant",content:t.assistantText,timestamp:Date.now()}),null===(l=this.onMessageReceived)||void 0===l||l.call(this,t.assistantText)}else this.displayInUI&&this.dispatchMessage({id:`m-${Date.now()}`,role:"assistant",content:t.assistantText,timestamp:Date.now()}),null===(r=this.onMessageReceived)||void 0===r||r.call(this,t.assistantText);return{responseId:m}}const{name:a,args:v,toolCallId:b,callId:I}=t.toolCall;console.log(`🔧 Tool call #${y}: ${a}`,v),b&&console.log(`🔧 Tool call ID: ${b}`),g.push({name:a,args:v,iteration:y}),b&&e.push({role:"assistant",text:"",toolCallId:b,toolName:a,toolArgs:JSON.stringify(v)});try{const t="string"==typeof v?(()=>{try{return JSON.parse(v)}catch(e){return v}})():v;null===(c=this.onMessageReceived)||void 0===c||c.call(this,{type:"TOOL_CALL",data:{name:a,args:t}});const n=yield this.functionHandler(a,t);if(b?e.push({role:"tool",text:JSON.stringify(n),toolCallId:b}):(console.warn("⚠️ No tool_call_id available for tool result"),e.push({role:"tool",text:JSON.stringify(n)})),I){const t="object"==typeof n&&null!==n?n:String(n),l=this.sanitizeToolOutput(a,t);try{const e="string"==typeof t?t:JSON.stringify(t);null===(d=this.onMessageReceived)||void 0===d||d.call(this,{type:"TOOL_RESULT",data:{name:a,preview:e.slice(0,1e3)}})}catch(e){}const r=[{type:"function_call_output",call_id:I,output:l}],c=yield s.callToChatbot(e,o,i,this.system.id,this.apiAdapter,m,this.system.functions,this.system.model,r,this.system.tools);if(m=c.responseId,!c.toolCall){if(c.assistantText)if("json"===this.responseFormat)try{const e=JSON.parse(c.assistantText);if(this.displayInUI){const t="string"==typeof(null==e?void 0:e.response)?e.response:c.assistantText;this.dispatchMessage({id:`m-${Date.now()}`,role:"assistant",content:t,timestamp:Date.now()})}null===(h=this.onMessageReceived)||void 0===h||h.call(this,e)}catch(e){this.displayInUI&&this.dispatchMessage({id:`m-${Date.now()}`,role:"assistant",content:c.assistantText,timestamp:Date.now()}),null===(u=this.onMessageReceived)||void 0===u||u.call(this,c.assistantText)}else this.displayInUI&&this.dispatchMessage({id:`m-${Date.now()}`,role:"assistant",content:c.assistantText,timestamp:Date.now()}),null===(p=this.onMessageReceived)||void 0===p||p.call(this,c.assistantText);return{responseId:m}}f=c}else console.warn("⚠️ No call_id provided by backend for tool chaining")}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:m}}}return this.displayInUI&&(console.warn(`⚠️ Maximum tool call iterations (${this.maxToolCalls}) reached. Tool calls made:`,g.map((e=>`${e.name} (iter ${e.iteration})`)).join(", ")||"none"),this.dispatchMessage({id:`m-${Date.now()}`,role:"system",content:`Maximum tool call iterations (${this.maxToolCalls}) reached.`,timestamp:Date.now()})),{responseId:m}}))}};
|
|
@@ -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[]): Promise<GenericAIResponse>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../../_virtual/_tslib.js");exports.callToChatbot=function(t){let o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"default",n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"default-session",i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:"generic",s=arguments.length>4?arguments[4]:void 0,r=arguments.length>5?arguments[5]:void 0,l=arguments.length>6?arguments[6]:void 0,a=arguments.length>7&&void 0!==arguments[7]?arguments[7]:"gpt-4o-mini-mini",d=arguments.length>8?arguments[8]:void 0,u=arguments.length>9?arguments[9]:void 0;return e.__awaiter(this,void 0,void 0,(function*(){if(!s)throw new Error("Chatbot authentication not configured: RequestExecutor is required");const e=d&&d.length>0?d:function(e){return e.map((e=>{let{role:t,text:o}=e;return{role:t,content:o}}))}(t),c={input:e,intent:o,conversationId:n,systemId:i,previousResponseId:r,customFunctions:l,builtinTools:u,model:a,maxTokens:4e3};return yield s(c)}))},exports.createExecutorApiAdapter=function(t,o){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"/openaiApiFunctions-callChatbot";return i=>e.__awaiter(this,void 0,void 0,(function*(){var e,s;const{input:r,model:l,maxTokens:a=4e3,previousResponseId:d,customFunctions:u,builtinTools:c}=i,p={input:r,tools:[...(c||[]).map((e=>({type:e}))),...(v=u,v&&0!==v.length?v.map((e=>({type:"function",name:e.name,description:e.description,parameters:e.parameters}))):[])],model:l,max_output_tokens:a,previous_response_id:d};var v;const h=`${o.replace(/\/$/,"")}${n}`,{status:m,data:g,error:f}=yield t.sendData({apiPath:h,apiMethod:"POST",requestBody:p});if(200!==m||!(null==g?void 0:g.success)){const t=(null===(s=null===(e=null==g?void 0:g.errors)||void 0===e?void 0:e[0])||void 0===s?void 0:s.message)||f;throw new Error("Backend error: "+(t?` - ${String(t)}`:""))}return function(e){const t={assistantText:e.assistantText,parsed:e.parsed,lastResponseId:e.lastResponseId,responseId:e.responseId};return e.toolCall&&(t.toolCall={name:e.toolCall.name,args:e.toolCall.args,toolCallId:e.toolCall.id,callId:e.toolCall.call_id}),t}(g.data)}))};
|
|
@@ -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
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../../_virtual/_tslib.js"),i=require("idb-keyval");const t="ai-session:";exports.loadSession=function(r){return e.__awaiter(this,void 0,void 0,(function*(){return(yield i.get(`${t}${r}`))||null}))},exports.saveSession=function(r,s){return e.__awaiter(this,void 0,void 0,(function*(){yield i.set(`${t}${r}`,s)}))};
|
|
@@ -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, 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
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("../../../_virtual/_tslib.js"),s=require("react"),t=require("../types/chat.js");require("../types/ai.js");var a=require("./aiService.js"),n=require("./db.js");exports.useAIChat=function(o){var i=this;let{system:r,conversationId:c,skipInitialization:l=!1,customFunctions:d,functionHandler:g,responseFormat:u,onMessageReceived:m,displayInUI:p,maxToolCalls:v,apiAdapter:b}=o;const[j,I]=s.useState((()=>t.createSessionRecord(c))),[O,y]=s.useState([]),[S,f]=s.useState(),[h,w]=s.useState(!1);s.useEffect((()=>{n.loadSession(c).then((e=>{var s;e&&(I(e),y(e.messages),f(null===(s=e.metadata)||void 0===s?void 0:s.lastResponseId))}))}),[c]);const A=s.useMemo((()=>l?(console.log("⏭️ Skipping AIService creation - system not ready"),null):(console.log("🔧 Creating AIService with system:",r.id,r.name),console.log("🔧 System prompt preview:",r.systemPrompt.substring(0,50)+"..."),console.log("🔧 useMemo triggered - system reference changed"),new a.AIService({system:Object.assign(Object.assign({},r),{handleCallback:(e,s)=>{var t;null===(t=r.handleCallback)||void 0===t||t.call(r,e,s)}}),dispatchMessage:e=>{y((s=>[...s,e])),I((s=>{const t=Object.assign(Object.assign({},s),{updatedAt:Date.now(),messages:[...s.messages,e]});return n.saveSession(t.sessionId,Object.assign(Object.assign({},t),{metadata:Object.assign(Object.assign({},t.metadata||{}),{lastResponseId:S})})),t}))},customFunctions:d,functionHandler:g,responseFormat:u,onMessageReceived:m,displayInUI:p,maxToolCalls:v,apiAdapter:b}))),[r.id,l]);return{messages:O,conversation:j,sendMessage:function(s){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"default";return e.__awaiter(i,void 0,void 0,(function*(){if(!A)return void console.warn("⚠️ AIService not ready - cannot send message");console.log("📤 Sending message with system:",r.id,r.name),console.log("📝 Message content:",s.substring(0,100)+"...");const e={id:`u-${Date.now()}`,role:"user",content:s,timestamp:Date.now()};y((s=>[...s,e])),I((s=>{const t=Object.assign(Object.assign({},s),{updatedAt:Date.now(),messages:[...s.messages,e]});return n.saveSession(t.sessionId,Object.assign(Object.assign({},t),{metadata:Object.assign(Object.assign({},t.metadata||{}),{lastResponseId:S})})),t})),w(!0);try{const s=yield A.generate([...O,e].map((e=>({role:e.role,content:e.content}))),c,t,S);(null==s?void 0:s.responseId)&&(f(s.responseId),I((e=>{const t=Object.assign(Object.assign({},e),{metadata:Object.assign(Object.assign({},e.metadata||{}),{lastResponseId:s.responseId})});return n.saveSession(t.sessionId,t),t})))}catch(e){console.error("Error sending message:",e)}finally{w(!1)}}))},isApiCallInProgress:h}};
|