@rohan_p31/ai-chat-sdk 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +75 -0
- package/lib/components/AIChat.d.ts +4 -0
- package/lib/components/AIChat.d.ts.map +1 -0
- package/lib/components/AIChat.js +117 -0
- package/lib/components/AIChat.js.map +1 -0
- package/lib/components/ChatInput.d.ts +11 -0
- package/lib/components/ChatInput.d.ts.map +1 -0
- package/lib/components/ChatInput.js +109 -0
- package/lib/components/ChatInput.js.map +1 -0
- package/lib/components/MessageBubble.d.ts +13 -0
- package/lib/components/MessageBubble.d.ts.map +1 -0
- package/lib/components/MessageBubble.js +107 -0
- package/lib/components/MessageBubble.js.map +1 -0
- package/lib/hooks/useChat.d.ts +11 -0
- package/lib/hooks/useChat.d.ts.map +1 -0
- package/lib/hooks/useChat.js +66 -0
- package/lib/hooks/useChat.js.map +1 -0
- package/lib/index.d.ts +9 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +19 -0
- package/lib/index.js.map +1 -0
- package/lib/services/MockChatService.d.ts +7 -0
- package/lib/services/MockChatService.d.ts.map +1 -0
- package/lib/services/MockChatService.js +23 -0
- package/lib/services/MockChatService.js.map +1 -0
- package/lib/theme/colors.d.ts +20 -0
- package/lib/theme/colors.d.ts.map +1 -0
- package/lib/theme/colors.js +42 -0
- package/lib/theme/colors.js.map +1 -0
- package/lib/types/Message.d.ts +20 -0
- package/lib/types/Message.d.ts.map +1 -0
- package/lib/types/Message.js +3 -0
- package/lib/types/Message.js.map +1 -0
- package/package.json +37 -0
- package/src/components/AIChat.tsx +139 -0
- package/src/components/ChatInput.tsx +116 -0
- package/src/components/MessageBubble.tsx +151 -0
- package/src/hooks/useChat.ts +77 -0
- package/src/index.ts +8 -0
- package/src/services/MockChatService.ts +31 -0
- package/src/theme/colors.ts +63 -0
- package/src/types/Message.ts +17 -0
package/README.md
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# @rohan_p31/ai-chat-sdk
|
|
2
|
+
|
|
3
|
+
React Native AI chat UI SDK with ChatGPT-style streaming simulation (mock backend for Phase 1).
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @rohan_p31/ai-chat-sdk
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
Peer dependencies: `react`, `react-native`.
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
```tsx
|
|
16
|
+
import { AIChat } from '@rohan_p31/ai-chat-sdk';
|
|
17
|
+
|
|
18
|
+
export default function App() {
|
|
19
|
+
return <AIChat />;
|
|
20
|
+
}
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Configurable
|
|
24
|
+
|
|
25
|
+
```tsx
|
|
26
|
+
<AIChat
|
|
27
|
+
assistantName="Smart Hire AI"
|
|
28
|
+
welcomeMessage="Hi, how can I help?"
|
|
29
|
+
theme="light"
|
|
30
|
+
primaryColor="#6200EE"
|
|
31
|
+
assistantAvatar={require('./assets/ai.png')}
|
|
32
|
+
userAvatar={require('./assets/user.png')}
|
|
33
|
+
/>
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### Props
|
|
37
|
+
|
|
38
|
+
| Prop | Type | Default | Description |
|
|
39
|
+
|------|------|---------|-------------|
|
|
40
|
+
| `assistantName` | `string` | `"AI Assistant"` | Header title |
|
|
41
|
+
| `welcomeMessage` | `string` | `"Hi, how can I help?"` | First AI message |
|
|
42
|
+
| `theme` | `"light" \| "dark"` | `"light"` | Color theme |
|
|
43
|
+
| `primaryColor` | `string` | `"#6200EE"` | Accent / user bubble / send button |
|
|
44
|
+
| `assistantAvatar` | image source | — | Optional AI avatar |
|
|
45
|
+
| `userAvatar` | image source | — | Optional user avatar |
|
|
46
|
+
|
|
47
|
+
## Features (Phase 1)
|
|
48
|
+
|
|
49
|
+
- Chat screen with message list and input
|
|
50
|
+
- Character-by-character streaming simulation
|
|
51
|
+
- Typing indicator (`AI is typing...`)
|
|
52
|
+
- Auto-scroll on new messages
|
|
53
|
+
- Light / dark theme and custom primary color
|
|
54
|
+
- Optional avatars
|
|
55
|
+
|
|
56
|
+
## Example app
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
cd example
|
|
60
|
+
npm install
|
|
61
|
+
npx react-native run-ios
|
|
62
|
+
# or
|
|
63
|
+
npx react-native run-android
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Development
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
npm install
|
|
70
|
+
npm run build
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
## License
|
|
74
|
+
|
|
75
|
+
MIT
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AIChat.d.ts","sourceRoot":"","sources":["../../src/components/AIChat.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAqC,MAAM,OAAO,CAAC;AAW1D,OAAO,KAAK,EAAE,WAAW,EAAW,MAAM,kBAAkB,CAAC;AAM7D,wBAAgB,MAAM,CAAC,EACrB,aAA8B,EAC9B,cAAsC,EACtC,KAAe,EACf,YAAwB,EACxB,eAAe,EACf,UAAU,GACX,EAAE,WAAW,qBAoFb"}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.AIChat = AIChat;
|
|
37
|
+
const react_1 = __importStar(require("react"));
|
|
38
|
+
const react_native_1 = require("react-native");
|
|
39
|
+
const colors_1 = require("../theme/colors");
|
|
40
|
+
const useChat_1 = require("../hooks/useChat");
|
|
41
|
+
const MessageBubble_1 = require("./MessageBubble");
|
|
42
|
+
const ChatInput_1 = require("./ChatInput");
|
|
43
|
+
function AIChat({ assistantName = 'AI Assistant', welcomeMessage = 'Hi, how can I help?', theme = 'light', primaryColor = '#6200EE', assistantAvatar, userAvatar, }) {
|
|
44
|
+
const colors = (0, react_1.useMemo)(() => (0, colors_1.getThemeColors)(theme, primaryColor), [theme, primaryColor]);
|
|
45
|
+
const { messages, isTyping, isStreaming, sendMessage } = (0, useChat_1.useChat)({
|
|
46
|
+
welcomeMessage,
|
|
47
|
+
});
|
|
48
|
+
const listRef = (0, react_1.useRef)(null);
|
|
49
|
+
(0, react_1.useEffect)(() => {
|
|
50
|
+
const timer = setTimeout(() => {
|
|
51
|
+
var _a;
|
|
52
|
+
(_a = listRef.current) === null || _a === void 0 ? void 0 : _a.scrollToEnd({ animated: true });
|
|
53
|
+
}, 50);
|
|
54
|
+
return () => clearTimeout(timer);
|
|
55
|
+
}, [messages, isTyping]);
|
|
56
|
+
const renderItem = ({ item }) => {
|
|
57
|
+
if (!item.isUser && item.text.length === 0) {
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
return (<MessageBubble_1.MessageBubble message={item} colors={colors} assistantAvatar={assistantAvatar} userAvatar={userAvatar}/>);
|
|
61
|
+
};
|
|
62
|
+
return (<react_native_1.SafeAreaView style={[styles.safe, { backgroundColor: colors.background }]}>
|
|
63
|
+
<react_native_1.KeyboardAvoidingView style={styles.flex} behavior={react_native_1.Platform.OS === 'ios' ? 'padding' : undefined} keyboardVerticalOffset={react_native_1.Platform.OS === 'ios' ? 8 : 0}>
|
|
64
|
+
<react_native_1.View style={[
|
|
65
|
+
styles.header,
|
|
66
|
+
{
|
|
67
|
+
backgroundColor: colors.headerBackground,
|
|
68
|
+
borderBottomColor: colors.separator,
|
|
69
|
+
},
|
|
70
|
+
]}>
|
|
71
|
+
<react_native_1.Text style={[styles.headerTitle, { color: colors.headerText }]}>
|
|
72
|
+
{assistantName}
|
|
73
|
+
</react_native_1.Text>
|
|
74
|
+
</react_native_1.View>
|
|
75
|
+
|
|
76
|
+
<react_native_1.FlatList ref={listRef} data={messages} keyExtractor={item => item.id} renderItem={renderItem} contentContainerStyle={styles.listContent} style={[styles.flex, { backgroundColor: colors.background }]} onContentSizeChange={() => { var _a; return (_a = listRef.current) === null || _a === void 0 ? void 0 : _a.scrollToEnd({ animated: true }); }} keyboardShouldPersistTaps="handled"/>
|
|
77
|
+
|
|
78
|
+
{isTyping && (<react_native_1.View style={styles.typingRow}>
|
|
79
|
+
<react_native_1.Text style={[styles.typingText, { color: colors.typingText }]}>
|
|
80
|
+
AI is typing...
|
|
81
|
+
</react_native_1.Text>
|
|
82
|
+
</react_native_1.View>)}
|
|
83
|
+
|
|
84
|
+
<ChatInput_1.ChatInput colors={colors} disabled={isStreaming} onSend={sendMessage}/>
|
|
85
|
+
</react_native_1.KeyboardAvoidingView>
|
|
86
|
+
</react_native_1.SafeAreaView>);
|
|
87
|
+
}
|
|
88
|
+
const styles = react_native_1.StyleSheet.create({
|
|
89
|
+
safe: {
|
|
90
|
+
flex: 1,
|
|
91
|
+
},
|
|
92
|
+
flex: {
|
|
93
|
+
flex: 1,
|
|
94
|
+
},
|
|
95
|
+
header: {
|
|
96
|
+
paddingHorizontal: 16,
|
|
97
|
+
paddingVertical: 14,
|
|
98
|
+
borderBottomWidth: react_native_1.StyleSheet.hairlineWidth,
|
|
99
|
+
},
|
|
100
|
+
headerTitle: {
|
|
101
|
+
fontSize: 17,
|
|
102
|
+
fontWeight: '700',
|
|
103
|
+
},
|
|
104
|
+
listContent: {
|
|
105
|
+
paddingVertical: 12,
|
|
106
|
+
flexGrow: 1,
|
|
107
|
+
},
|
|
108
|
+
typingRow: {
|
|
109
|
+
paddingHorizontal: 20,
|
|
110
|
+
paddingBottom: 6,
|
|
111
|
+
},
|
|
112
|
+
typingText: {
|
|
113
|
+
fontSize: 13,
|
|
114
|
+
fontStyle: 'italic',
|
|
115
|
+
},
|
|
116
|
+
});
|
|
117
|
+
//# sourceMappingURL=AIChat.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AIChat.js","sourceRoot":"","sources":["../../src/components/AIChat.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiBA,wBA2FC;AA5GD,+CAA0D;AAC1D,+CASsB;AAEtB,4CAAiD;AACjD,8CAA2C;AAC3C,mDAAgD;AAChD,2CAAwC;AAExC,SAAgB,MAAM,CAAC,EACrB,aAAa,GAAG,cAAc,EAC9B,cAAc,GAAG,qBAAq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ors } from '../theme/colors';
|
|
4
|
+
export interface ChatInputProps {
|
|
5
|
+
colors: ThemeColors;
|
|
6
|
+
disabled?: boolean;
|
|
7
|
+
onSend: (text: string) => void;
|
|
8
|
+
style?: StyleProp<ViewStyle>;
|
|
9
|
+
}
|
|
10
|
+
export declare function ChatInput({ colors, disabled, onSend, style, }: ChatInputProps): React.JSX.Element;
|
|
11
|
+
//# sourceMappingURL=ChatInput.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ChatInput.d.ts","sourceRoot":"","sources":["../../src/components/ChatInput.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAmB,MAAM,OAAO,CAAC;AACxC,OAAO,EAML,KAAK,SAAS,EACd,KAAK,SAAS,EACf,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAEnD,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,WAAW,CAAC;IACpB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAC/B,KAAK,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;CAC9B;AAED,wBAAgB,SAAS,CAAC,EACxB,MAAM,EACN,QAAgB,EAChB,MAAM,EACN,KAAK,GACN,EAAE,cAAc,qBA0DhB"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.ChatInput = ChatInput;
|
|
37
|
+
const react_1 = __importStar(require("react"));
|
|
38
|
+
const react_native_1 = require("react-native");
|
|
39
|
+
function ChatInput({ colors, disabled = false, onSend, style, }) {
|
|
40
|
+
const [text, setText] = (0, react_1.useState)('');
|
|
41
|
+
const handleSend = () => {
|
|
42
|
+
const trimmed = text.trim();
|
|
43
|
+
if (!trimmed || disabled) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
onSend(trimmed);
|
|
47
|
+
setText('');
|
|
48
|
+
};
|
|
49
|
+
const canSend = text.trim().length > 0 && !disabled;
|
|
50
|
+
return (<react_native_1.View style={[
|
|
51
|
+
styles.container,
|
|
52
|
+
{
|
|
53
|
+
backgroundColor: colors.surface,
|
|
54
|
+
borderTopColor: colors.separator,
|
|
55
|
+
},
|
|
56
|
+
style,
|
|
57
|
+
]}>
|
|
58
|
+
<react_native_1.TextInput value={text} onChangeText={setText} placeholder="Type Message..." placeholderTextColor={colors.placeholder} editable={!disabled} multiline style={[
|
|
59
|
+
styles.input,
|
|
60
|
+
{
|
|
61
|
+
backgroundColor: colors.inputBackground,
|
|
62
|
+
borderColor: colors.inputBorder,
|
|
63
|
+
color: colors.inputText,
|
|
64
|
+
},
|
|
65
|
+
]} onSubmitEditing={handleSend} blurOnSubmit={false}/>
|
|
66
|
+
<react_native_1.Pressable onPress={handleSend} disabled={!canSend} style={({ pressed }) => [
|
|
67
|
+
styles.sendButton,
|
|
68
|
+
{
|
|
69
|
+
backgroundColor: canSend ? colors.primary : colors.inputBorder,
|
|
70
|
+
opacity: pressed && canSend ? 0.85 : 1,
|
|
71
|
+
},
|
|
72
|
+
]}>
|
|
73
|
+
<react_native_1.Text style={styles.sendLabel}>Send</react_native_1.Text>
|
|
74
|
+
</react_native_1.Pressable>
|
|
75
|
+
</react_native_1.View>);
|
|
76
|
+
}
|
|
77
|
+
const styles = react_native_1.StyleSheet.create({
|
|
78
|
+
container: {
|
|
79
|
+
flexDirection: 'row',
|
|
80
|
+
alignItems: 'flex-end',
|
|
81
|
+
paddingHorizontal: 12,
|
|
82
|
+
paddingVertical: 10,
|
|
83
|
+
borderTopWidth: react_native_1.StyleSheet.hairlineWidth,
|
|
84
|
+
gap: 8,
|
|
85
|
+
},
|
|
86
|
+
input: {
|
|
87
|
+
flex: 1,
|
|
88
|
+
minHeight: 40,
|
|
89
|
+
maxHeight: 120,
|
|
90
|
+
borderWidth: 1,
|
|
91
|
+
borderRadius: 20,
|
|
92
|
+
paddingHorizontal: 14,
|
|
93
|
+
paddingVertical: 10,
|
|
94
|
+
fontSize: 15,
|
|
95
|
+
},
|
|
96
|
+
sendButton: {
|
|
97
|
+
height: 40,
|
|
98
|
+
paddingHorizontal: 16,
|
|
99
|
+
borderRadius: 20,
|
|
100
|
+
alignItems: 'center',
|
|
101
|
+
justifyContent: 'center',
|
|
102
|
+
},
|
|
103
|
+
sendLabel: {
|
|
104
|
+
color: '#FFFFFF',
|
|
105
|
+
fontSize: 14,
|
|
106
|
+
fontWeight: '600',
|
|
107
|
+
},
|
|
108
|
+
});
|
|
109
|
+
//# sourceMappingURL=ChatInput.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ChatInput.js","sourceRoot":"","sources":["../../src/components/ChatInput.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmBA,8BA+DC;AAlFD,+CAAwC;AACxC,+CAQsB;AAUtB,SAAgB,SAAS,CAAC,EACxB,MAAM,EACN,QAAQ,GAAG,KAAK,EAChB,MAAM,EACN,KAAK,GACU;IACf,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,IAAA,gBAAQ,EAAC,EAAE,CAAC,CAAC;IAErC,MAAM,UAAU,GAAG,GAAG,EAAE;QACtB,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;QAC5B,IAAI,CAAC,OAAO,IAAI,QAAQ,EAAE,CAAC;YACzB,OAAO;QACT,CAAC;QACD,MAAM,CAAC,OAAO,CAAC,CAAC;QAChB,OAAO,CAAC,EAAE,CAAC,CAAC;IACd,CAAC,CAAC;IAEF,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC;IAEpD,OAAO,CACL,CAAC,mBAAI,CACH,KAAK,CAAC,CAAC;YACL,MAAM,CAAC,SAAS;YAChB;gBACE,eAAe,EAAE,MAAM,CAAC,OAAO;gBAC/B,cAAc,EAAE,MAAM,CAAC,SAAS;aACjC;YACD,KAAK;SACN,CAAC,CAEF;MAAA,CAAC,wBAAS,CACR,KAAK,CAAC,CAAC,IAAI,CAAC,CACZ,YAAY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,EAAE;QACL,IAAI,EAAE,CAAC;QACP,SAAS,EAAE,EAAE;QACb,SAAS,EAAE,GAAG;QACd,WAAW,EAAE,CAAC;QACd,YAAY,EAAE,EAAE;QAChB,iBAAiB,EAAE,EAAE;QACrB,eAAe,EAAE,EAAE;QACnB,QAAQ,EAAE,EAAE;KACb;IACD,UAAU,EAAE;QACV,MAAM,EAAE,EAAE;QACV,iBAAiB,EAAE,EAAE;QACrB,YAAY,EAAE,EAAE;QAChB,UAAU,EAAE,QAAQ;QACpB,cAAc,EAAE,QAAQ;KACzB;IACD,SAAS,EAAE;QACT,KAAK,EAAE,SAAS;QAChB,QAAQ,EAAE,EAAE;QACZ,UAAU,EAAE,KAAK;KAClB;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { type ImageSourcePropType, type StyleProp, type ViewStyle } from 'react-native';
|
|
3
|
+
import type { Message } from '../types/Message';
|
|
4
|
+
import type { ThemeColors } from '../theme/colors';
|
|
5
|
+
export interface MessageBubbleProps {
|
|
6
|
+
message: Message;
|
|
7
|
+
colors: ThemeColors;
|
|
8
|
+
assistantAvatar?: ImageSourcePropType;
|
|
9
|
+
userAvatar?: ImageSourcePropType;
|
|
10
|
+
style?: StyleProp<ViewStyle>;
|
|
11
|
+
}
|
|
12
|
+
export declare function MessageBubble({ message, colors, assistantAvatar, userAvatar, style, }: MessageBubbleProps): React.JSX.Element;
|
|
13
|
+
//# sourceMappingURL=MessageBubble.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MessageBubble.d.ts","sourceRoot":"","sources":["../../src/components/MessageBubble.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAKL,KAAK,mBAAmB,EACxB,KAAK,SAAS,EACd,KAAK,SAAS,EACf,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAEnD,MAAM,WAAW,kBAAkB;IACjC,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,WAAW,CAAC;IACpB,eAAe,CAAC,EAAE,mBAAmB,CAAC;IACtC,UAAU,CAAC,EAAE,mBAAmB,CAAC;IACjC,KAAK,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;CAC9B;AAED,wBAAgB,aAAa,CAAC,EAC5B,OAAO,EACP,MAAM,EACN,eAAe,EACf,UAAU,EACV,KAAK,GACN,EAAE,kBAAkB,qBAsEpB"}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.MessageBubble = MessageBubble;
|
|
7
|
+
const react_1 = __importDefault(require("react"));
|
|
8
|
+
const react_native_1 = require("react-native");
|
|
9
|
+
function MessageBubble({ message, colors, assistantAvatar, userAvatar, style, }) {
|
|
10
|
+
const isUser = message.isUser;
|
|
11
|
+
const avatar = isUser ? userAvatar : assistantAvatar;
|
|
12
|
+
return (<react_native_1.View style={[
|
|
13
|
+
styles.row,
|
|
14
|
+
isUser ? styles.rowUser : styles.rowAssistant,
|
|
15
|
+
style,
|
|
16
|
+
]}>
|
|
17
|
+
{!isUser && (<react_native_1.View style={styles.avatarSlot}>
|
|
18
|
+
{avatar ? (<react_native_1.Image source={avatar} style={styles.avatar}/>) : (<react_native_1.View style={[
|
|
19
|
+
styles.avatarPlaceholder,
|
|
20
|
+
{ backgroundColor: colors.assistantBubble },
|
|
21
|
+
]}>
|
|
22
|
+
<react_native_1.Text style={[styles.avatarLetter, { color: colors.assistantText }]}>
|
|
23
|
+
AI
|
|
24
|
+
</react_native_1.Text>
|
|
25
|
+
</react_native_1.View>)}
|
|
26
|
+
</react_native_1.View>)}
|
|
27
|
+
|
|
28
|
+
<react_native_1.View style={[
|
|
29
|
+
styles.bubble,
|
|
30
|
+
{
|
|
31
|
+
backgroundColor: isUser ? colors.userBubble : colors.assistantBubble,
|
|
32
|
+
},
|
|
33
|
+
isUser ? styles.bubbleUser : styles.bubbleAssistant,
|
|
34
|
+
]}>
|
|
35
|
+
<react_native_1.Text style={[
|
|
36
|
+
styles.text,
|
|
37
|
+
{ color: isUser ? colors.userText : colors.assistantText },
|
|
38
|
+
]}>
|
|
39
|
+
{message.text}
|
|
40
|
+
</react_native_1.Text>
|
|
41
|
+
</react_native_1.View>
|
|
42
|
+
|
|
43
|
+
{isUser && (<react_native_1.View style={styles.avatarSlot}>
|
|
44
|
+
{avatar ? (<react_native_1.Image source={avatar} style={styles.avatar}/>) : (<react_native_1.View style={[
|
|
45
|
+
styles.avatarPlaceholder,
|
|
46
|
+
{ backgroundColor: colors.primary },
|
|
47
|
+
]}>
|
|
48
|
+
<react_native_1.Text style={[styles.avatarLetter, { color: colors.userText }]}>
|
|
49
|
+
U
|
|
50
|
+
</react_native_1.Text>
|
|
51
|
+
</react_native_1.View>)}
|
|
52
|
+
</react_native_1.View>)}
|
|
53
|
+
</react_native_1.View>);
|
|
54
|
+
}
|
|
55
|
+
const styles = react_native_1.StyleSheet.create({
|
|
56
|
+
row: {
|
|
57
|
+
flexDirection: 'row',
|
|
58
|
+
alignItems: 'flex-end',
|
|
59
|
+
marginVertical: 4,
|
|
60
|
+
paddingHorizontal: 12,
|
|
61
|
+
maxWidth: '100%',
|
|
62
|
+
},
|
|
63
|
+
rowUser: {
|
|
64
|
+
justifyContent: 'flex-end',
|
|
65
|
+
},
|
|
66
|
+
rowAssistant: {
|
|
67
|
+
justifyContent: 'flex-start',
|
|
68
|
+
},
|
|
69
|
+
avatarSlot: {
|
|
70
|
+
width: 32,
|
|
71
|
+
height: 32,
|
|
72
|
+
marginHorizontal: 6,
|
|
73
|
+
},
|
|
74
|
+
avatar: {
|
|
75
|
+
width: 32,
|
|
76
|
+
height: 32,
|
|
77
|
+
borderRadius: 16,
|
|
78
|
+
},
|
|
79
|
+
avatarPlaceholder: {
|
|
80
|
+
width: 32,
|
|
81
|
+
height: 32,
|
|
82
|
+
borderRadius: 16,
|
|
83
|
+
alignItems: 'center',
|
|
84
|
+
justifyContent: 'center',
|
|
85
|
+
},
|
|
86
|
+
avatarLetter: {
|
|
87
|
+
fontSize: 11,
|
|
88
|
+
fontWeight: '700',
|
|
89
|
+
},
|
|
90
|
+
bubble: {
|
|
91
|
+
maxWidth: '72%',
|
|
92
|
+
borderRadius: 16,
|
|
93
|
+
paddingHorizontal: 14,
|
|
94
|
+
paddingVertical: 10,
|
|
95
|
+
},
|
|
96
|
+
bubbleUser: {
|
|
97
|
+
borderBottomRightRadius: 4,
|
|
98
|
+
},
|
|
99
|
+
bubbleAssistant: {
|
|
100
|
+
borderBottomLeftRadius: 4,
|
|
101
|
+
},
|
|
102
|
+
text: {
|
|
103
|
+
fontSize: 15,
|
|
104
|
+
lineHeight: 21,
|
|
105
|
+
},
|
|
106
|
+
});
|
|
107
|
+
//# sourceMappingURL=MessageBubble.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MessageBubble.js","sourceRoot":"","sources":["../../src/components/MessageBubble.tsx"],"names":[],"mappings":";;;;;AAqBA,sCA4EC;AAjGD,kDAA0B;AAC1B,+CAQsB;AAYtB,SAAgB,aAAa,CAAC,EAC5B,OAAO,EACP,MAAM,EACN,eAAe,EACf,UAAU,EACV,KAAK,GACc;IACnB,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAC9B,MAAM,MAAM,GAAG,MAAM,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,eAAe,CAAC;IAErD,OAAO,CACL,CAAC,mBAAI,CACH,KAAK,CAAC,CAAC;YACL,MAAM,CAAC,GAAG;YACV,MAAM,CAAC,CAAC,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K,EAAE,EAAE;QACT,MAAM,EAAE,EAAE;QACV,YAAY,EAAE,EAAE;QAChB,UAAU,EAAE,QAAQ;QACpB,cAAc,EAAE,QAAQ;KACzB;IACD,YAAY,EAAE;QACZ,QAAQ,EAAE,EAAE;QACZ,UAAU,EAAE,KAAK;KAClB;IACD,MAAM,EAAE;QACN,QAAQ,EAAE,KAAK;QACf,YAAY,EAAE,EAAE;QAChB,iBAAiB,EAAE,EAAE;QACrB,eAAe,EAAE,EAAE;KACpB;IACD,UAAU,EAAE;QACV,uBAAuB,EAAE,CAAC;KAC3B;IACD,eAAe,EAAE;QACf,sBAAsB,EAAE,CAAC;KAC1B;IACD,IAAI,EAAE;QACJ,QAAQ,EAAE,EAAE;QACZ,UAAU,EAAE,EAAE;KACf;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Message } from '../types/Message';
|
|
2
|
+
export interface UseChatOptions {
|
|
3
|
+
welcomeMessage?: string;
|
|
4
|
+
}
|
|
5
|
+
export declare function useChat(options?: UseChatOptions): {
|
|
6
|
+
messages: Message[];
|
|
7
|
+
isTyping: boolean;
|
|
8
|
+
isStreaming: boolean;
|
|
9
|
+
sendMessage: (text: string) => Promise<void>;
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=useChat.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useChat.d.ts","sourceRoot":"","sources":["../../src/hooks/useChat.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAOhD,MAAM,WAAW,cAAc;IAC7B,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,wBAAgB,OAAO,CAAC,OAAO,GAAE,cAAmB;;;;wBAeL,MAAM;EAiDpD"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.useChat = useChat;
|
|
7
|
+
const react_1 = require("react");
|
|
8
|
+
const MockChatService_1 = __importDefault(require("../services/MockChatService"));
|
|
9
|
+
function createId() {
|
|
10
|
+
return `${Date.now()}-${Math.random().toString(36).slice(2, 9)}`;
|
|
11
|
+
}
|
|
12
|
+
function useChat(options = {}) {
|
|
13
|
+
const { welcomeMessage = 'Hi, how can I help?' } = options;
|
|
14
|
+
const [messages, setMessages] = (0, react_1.useState)(() => [
|
|
15
|
+
{
|
|
16
|
+
id: createId(),
|
|
17
|
+
text: welcomeMessage,
|
|
18
|
+
isUser: false,
|
|
19
|
+
timestamp: Date.now(),
|
|
20
|
+
},
|
|
21
|
+
]);
|
|
22
|
+
const [isTyping, setIsTyping] = (0, react_1.useState)(false);
|
|
23
|
+
const [isStreaming, setIsStreaming] = (0, react_1.useState)(false);
|
|
24
|
+
const busyRef = (0, react_1.useRef)(false);
|
|
25
|
+
const sendMessage = (0, react_1.useCallback)(async (text) => {
|
|
26
|
+
const trimmed = text.trim();
|
|
27
|
+
if (!trimmed || busyRef.current) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
busyRef.current = true;
|
|
31
|
+
const userMessage = {
|
|
32
|
+
id: createId(),
|
|
33
|
+
text: trimmed,
|
|
34
|
+
isUser: true,
|
|
35
|
+
timestamp: Date.now(),
|
|
36
|
+
};
|
|
37
|
+
const assistantId = createId();
|
|
38
|
+
const assistantMessage = {
|
|
39
|
+
id: assistantId,
|
|
40
|
+
text: '',
|
|
41
|
+
isUser: false,
|
|
42
|
+
timestamp: Date.now(),
|
|
43
|
+
};
|
|
44
|
+
setMessages(prev => [...prev, userMessage, assistantMessage]);
|
|
45
|
+
setIsTyping(true);
|
|
46
|
+
setIsStreaming(true);
|
|
47
|
+
try {
|
|
48
|
+
await MockChatService_1.default.streamMessage(trimmed, partialText => {
|
|
49
|
+
setIsTyping(false);
|
|
50
|
+
setMessages(prev => prev.map(msg => msg.id === assistantId ? { ...msg, text: partialText } : msg));
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
finally {
|
|
54
|
+
setIsTyping(false);
|
|
55
|
+
setIsStreaming(false);
|
|
56
|
+
busyRef.current = false;
|
|
57
|
+
}
|
|
58
|
+
}, []);
|
|
59
|
+
return {
|
|
60
|
+
messages,
|
|
61
|
+
isTyping,
|
|
62
|
+
isStreaming,
|
|
63
|
+
sendMessage,
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=useChat.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useChat.js","sourceRoot":"","sources":["../../src/hooks/useChat.ts"],"names":[],"mappings":";;;;;AAYA,0BAgEC;AA5ED,iCAAsD;AAEtD,kFAA0D;AAE1D,SAAS,QAAQ;IACf,OAAO,GAAG,IAAI,CAAC,GAAG,EAAE,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC;AACnE,CAAC;AAMD,SAAgB,OAAO,CAAC,UAA0B,EAAE;IAClD,MAAM,EAAE,cAAc,GAAG,qBAAqB,EAAE,GAAG,OAAO,CAAC;IAE3D,MAAM,CAAC,QAAQ,EAAE,WAAW,CAAC,GAAG,IAAA,gBAAQ,EAAY,GAAG,EAAE,CAAC;QACxD;YACE,EAAE,EAAE,QAAQ,EAAE;YACd,IAAI,EAAE,cAAc;YACpB,MAAM,EAAE,KAAK;YACb,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;SACtB;KACF,CAAC,CAAC;IACH,MAAM,CAAC,QAAQ,EAAE,WAAW,CAAC,GAAG,IAAA,gBAAQ,EAAC,KAAK,CAAC,CAAC;IAChD,MAAM,CAAC,WAAW,EAAE,cAAc,CAAC,GAAG,IAAA,gBAAQ,EAA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CAAC;QACL,CAAC;gBAAS,CAAC;YACT,WAAW,CAAC,KAAK,CAAC,CAAC;YACnB,cAAc,CAAC,KAAK,CAAC,CAAC;YACtB,OAAO,CAAC,OAAO,GAAG,KAAK,CAAC;QAC1B,CAAC;IACH,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO;QACL,QAAQ;QACR,QAAQ;QACR,WAAW;QACX,WAAW;KACZ,CAAC;AACJ,CAAC"}
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { AIChat } from './components/AIChat';
|
|
2
|
+
export { MessageBubble } from './components/MessageBubble';
|
|
3
|
+
export { ChatInput } from './components/ChatInput';
|
|
4
|
+
export { useChat } from './hooks/useChat';
|
|
5
|
+
export { default as MockChatService } from './services/MockChatService';
|
|
6
|
+
export { getThemeColors } from './theme/colors';
|
|
7
|
+
export type { Message, AIChatProps, ChatTheme } from './types/Message';
|
|
8
|
+
export type { ThemeColors } from './theme/colors';
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC1C,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,4BAA4B,CAAC;AACxE,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAChD,YAAY,EAAE,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACvE,YAAY,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC"}
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getThemeColors = exports.MockChatService = exports.useChat = exports.ChatInput = exports.MessageBubble = exports.AIChat = void 0;
|
|
7
|
+
var AIChat_1 = require("./components/AIChat");
|
|
8
|
+
Object.defineProperty(exports, "AIChat", { enumerable: true, get: function () { return AIChat_1.AIChat; } });
|
|
9
|
+
var MessageBubble_1 = require("./components/MessageBubble");
|
|
10
|
+
Object.defineProperty(exports, "MessageBubble", { enumerable: true, get: function () { return MessageBubble_1.MessageBubble; } });
|
|
11
|
+
var ChatInput_1 = require("./components/ChatInput");
|
|
12
|
+
Object.defineProperty(exports, "ChatInput", { enumerable: true, get: function () { return ChatInput_1.ChatInput; } });
|
|
13
|
+
var useChat_1 = require("./hooks/useChat");
|
|
14
|
+
Object.defineProperty(exports, "useChat", { enumerable: true, get: function () { return useChat_1.useChat; } });
|
|
15
|
+
var MockChatService_1 = require("./services/MockChatService");
|
|
16
|
+
Object.defineProperty(exports, "MockChatService", { enumerable: true, get: function () { return __importDefault(MockChatService_1).default; } });
|
|
17
|
+
var colors_1 = require("./theme/colors");
|
|
18
|
+
Object.defineProperty(exports, "getThemeColors", { enumerable: true, get: function () { return colors_1.getThemeColors; } });
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,8CAA6C;AAApC,gGAAA,MAAM,OAAA;AACf,4DAA2D;AAAlD,8GAAA,aAAa,OAAA;AACtB,oDAAmD;AAA1C,sGAAA,SAAS,OAAA;AAClB,2CAA0C;AAAjC,kGAAA,OAAO,OAAA;AAChB,8DAAwE;AAA/D,mIAAA,OAAO,OAAmB;AACnC,yCAAgD;AAAvC,wGAAA,cAAc,OAAA"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
declare class MockChatService {
|
|
2
|
+
sendMessage(message: string): Promise<string>;
|
|
3
|
+
streamMessage(message: string, onChunk: (partialText: string) => void): Promise<string>;
|
|
4
|
+
}
|
|
5
|
+
declare const _default: MockChatService;
|
|
6
|
+
export default _default;
|
|
7
|
+
//# sourceMappingURL=MockChatService.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MockChatService.d.ts","sourceRoot":"","sources":["../../src/services/MockChatService.ts"],"names":[],"mappings":"AAEA,cAAM,eAAe;IACb,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAK7C,aAAa,CACjB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,CAAC,WAAW,EAAE,MAAM,KAAK,IAAI,GACrC,OAAO,CAAC,MAAM,CAAC;CAiBnB;;AAED,wBAAqC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms));
|
|
4
|
+
class MockChatService {
|
|
5
|
+
async sendMessage(message) {
|
|
6
|
+
await sleep(1500);
|
|
7
|
+
return `Dummy response for: ${message}`;
|
|
8
|
+
}
|
|
9
|
+
async streamMessage(message, onChunk) {
|
|
10
|
+
await sleep(600);
|
|
11
|
+
const dummyResponse = `Hello! This is a dummy streaming response for: "${message}". ` +
|
|
12
|
+
'In a real integration, this text would come from your AI backend.';
|
|
13
|
+
let currentText = '';
|
|
14
|
+
for (let i = 0; i < dummyResponse.length; i++) {
|
|
15
|
+
currentText += dummyResponse[i];
|
|
16
|
+
onChunk(currentText);
|
|
17
|
+
await sleep(30);
|
|
18
|
+
}
|
|
19
|
+
return currentText;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
exports.default = new MockChatService();
|
|
23
|
+
//# sourceMappingURL=MockChatService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MockChatService.js","sourceRoot":"","sources":["../../src/services/MockChatService.ts"],"names":[],"mappings":";;AAAA,MAAM,KAAK,GAAG,CAAC,EAAU,EAAE,EAAE,CAAC,IAAI,OAAO,CAAO,OAAO,CAAC,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;AAEpF,MAAM,eAAe;IACnB,KAAK,CAAC,WAAW,CAAC,OAAe;QAC/B,MAAM,KAAK,CAAC,IAAI,CAAC,CAAC;QAClB,OAAO,uBAAuB,OAAO,EAAE,CAAC;IAC1C,CAAC;IAED,KAAK,CAAC,aAAa,CACjB,OAAe,EACf,OAAsC;QAEtC,MAAM,KAAK,CAAC,GAAG,CAAC,CAAC;QAEjB,MAAM,aAAa,GACjB,mDAAmD,OAAO,KAAK;YAC/D,mEAAmE,CAAC;QAEtE,IAAI,WAAW,GAAG,EAAE,CAAC;QAErB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,aAAa,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YAC9C,WAAW,IAAI,aAAa,CAAC,CAAC,CAAC,CAAC;YAChC,OAAO,CAAC,WAAW,CAAC,CAAC;YACrB,MAAM,KAAK,CAAC,EAAE,CAAC,CAAC;QAClB,CAAC;QAED,OAAO,WAAW,CAAC;IACrB,CAAC;CACF;AAED,kBAAe,IAAI,eAAe,EAAE,CAAC"}
|