@schmitech/chatbot-api 0.4.4 โ†’ 0.4.5

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.
Files changed (2) hide show
  1. package/README.md +78 -146
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,124 +1,51 @@
1
- # ๐Ÿค– Chatbot API Client
1
+ # ๐Ÿค– ORBIT Chatbot API Client
2
2
 
3
- A JavaScript/TypeScript client for seamless interaction with the Chatbot server, now supporting API key authentication and session tracking.
4
-
5
- ---
3
+ A TypeScript/JavaScript client for seamless interaction with the ORBIT server, supporting API key authentication and session tracking.
6
4
 
7
5
  ## ๐Ÿ“ฅ Installation
8
6
 
9
- ### ๐Ÿ“ Local Development (npm link)
10
-
11
- Use during local development:
12
-
13
7
  ```bash
14
- npm run build
15
- npm link
16
-
17
- # In your project directory
18
- npm link @schmitech/chatbot-api
19
- ```
20
-
21
- ### ๐Ÿ“‚ Local Directory Install
22
-
23
- Direct local installation:
24
-
25
- ```bash
26
- npm run build
27
- npm install /path/to/qa-chatbot-server/api
28
- ```
29
-
30
- ### ๐ŸŒ CDN Integration
31
-
32
- Integrate directly into websites via CDN:
33
-
34
- ```html
35
- <script type="module">
36
- import { configureApi, streamChat } from 'https://cdn.jsdelivr.net/npm/@schmitech/chatbot-api/dist/api.mjs';
37
-
38
- configureApi({
39
- apiUrl: 'https://your-api-server.com',
40
- apiKey: 'your-api-key',
41
- sessionId: 'your-session-id' // Optional
42
- });
43
-
44
- async function handleChat() {
45
- for await (const response of streamChat('Hello', false)) {
46
- console.log(response.text);
47
- }
48
- }
49
- </script>
8
+ npm install @schmitech/chatbot-api
50
9
  ```
51
10
 
52
- ---
53
-
54
- ## โš™๏ธ Usage
11
+ ## โš™๏ธ Basic Usage
55
12
 
56
- ### ๐Ÿšจ Configuration (Required)
13
+ ### Configuration
57
14
 
58
- You must configure the API client before usage:
15
+ First, configure the API client with your server details:
59
16
 
60
- ```javascript
17
+ ```typescript
61
18
  import { configureApi, streamChat } from '@schmitech/chatbot-api';
62
19
 
63
20
  configureApi({
64
21
  apiUrl: 'https://your-api-server.com',
65
22
  apiKey: 'your-api-key',
66
- sessionId: 'your-session-id' // Optional
23
+ sessionId: 'optional-session-id' // Optional, for conversation tracking
67
24
  });
68
25
  ```
69
26
 
70
- ### ๐Ÿ“– Basic Example
27
+ ### Streaming Chat Example
71
28
 
72
- ```javascript
29
+ ```typescript
73
30
  async function chat() {
74
- configureApi({
75
- apiUrl: 'https://your-api-server.com',
76
- apiKey: 'your-api-key',
77
- sessionId: 'user_123_session_456' // Optional
78
- });
79
-
80
- for await (const response of streamChat('Hello, how can I help?', false)) {
31
+ for await (const response of streamChat('Hello, how can I help?', true)) {
81
32
  console.log(response.text);
82
- if (response.done) console.log('Chat complete!');
83
- }
84
- }
85
-
86
- chat();
87
- ```
88
-
89
- ### ๐ŸŽ™๏ธ Voice-enabled Example
90
-
91
- ```javascript
92
- async function chatWithVoice() {
93
- configureApi({
94
- apiUrl: 'https://your-api-server.com',
95
- apiKey: 'your-api-key',
96
- sessionId: 'user_123_session_456' // Optional
97
- });
98
-
99
- for await (const response of streamChat('Tell me a joke', true)) {
100
- if (response.type === 'audio') {
101
- console.log('Received audio content');
102
- } else {
103
- console.log(response.text);
33
+ if (response.done) {
34
+ console.log('Chat complete!');
104
35
  }
105
- if (response.done) console.log('Chat complete!');
106
36
  }
107
37
  }
108
-
109
- chatWithVoice();
110
38
  ```
111
39
 
112
- ---
113
-
114
40
  ## โš›๏ธ React Integration
115
41
 
116
- Configure once globally:
42
+ Here's how to use the API in a React component:
117
43
 
118
- ```jsx
44
+ ```tsx
119
45
  import React, { useState } from 'react';
120
46
  import { configureApi, streamChat } from '@schmitech/chatbot-api';
121
47
 
48
+ // Configure once at app startup
122
49
  configureApi({
123
50
  apiUrl: 'https://your-api-server.com',
124
51
  apiKey: 'your-api-key',
@@ -126,15 +53,15 @@ configureApi({
126
53
  });
127
54
 
128
55
  function ChatComponent() {
129
- const [messages, setMessages] = useState([]);
56
+ const [messages, setMessages] = useState<Array<{ text: string; isUser: boolean }>>([]);
130
57
  const [input, setInput] = useState('');
131
58
 
132
- const handleSubmit = async (e) => {
59
+ const handleSubmit = async (e: React.FormEvent) => {
133
60
  e.preventDefault();
134
61
  setMessages(prev => [...prev, { text: input, isUser: true }]);
135
62
 
136
63
  let responseText = '';
137
- for await (const response of streamChat(input, false)) {
64
+ for await (const response of streamChat(input, true)) {
138
65
  responseText += response.text;
139
66
  setMessages(prev => [...prev, { text: responseText, isUser: false }]);
140
67
  if (response.done) break;
@@ -144,91 +71,96 @@ function ChatComponent() {
144
71
 
145
72
  return (
146
73
  <form onSubmit={handleSubmit}>
147
- <input value={input} onChange={(e) => setInput(e.target.value)} />
74
+ <input
75
+ value={input}
76
+ onChange={(e) => setInput(e.target.value)}
77
+ placeholder="Type your message..."
78
+ />
148
79
  <button type="submit">Send</button>
149
80
  </form>
150
81
  );
151
82
  }
152
-
153
- export default ChatComponent;
154
83
  ```
155
84
 
156
- ---
157
-
158
85
  ## ๐Ÿ“ฑ Mobile Usage
159
86
 
160
- ### ๐Ÿ“ฒ React Native
87
+ ### React Native Example
88
+
89
+ ```typescript
90
+ import { configureApi, streamChat } from '@schmitech/chatbot-api';
161
91
 
162
- ```javascript
163
- configureApi({
164
- apiUrl: 'https://your-api-server.com',
92
+ // Configure once at app startup
93
+ configureApi({
94
+ apiUrl: 'https://your-api-server.com',
165
95
  apiKey: 'your-api-key',
166
96
  sessionId: 'user_123_session_456' // Optional
167
97
  });
168
98
 
169
- async function handleChat(message) {
170
- for await (const response of streamChat(message, false)) {
171
- // Handle response
99
+ async function handleChat(message: string) {
100
+ for await (const response of streamChat(message, true)) {
101
+ // Handle streaming response
102
+ console.log(response.text);
103
+ if (response.done) {
104
+ console.log('Chat complete!');
105
+ }
172
106
  }
173
107
  }
174
108
  ```
175
109
 
176
- ---
110
+ ## ๐ŸŒ CDN Integration
177
111
 
178
- ## ๐Ÿ“š API Reference
112
+ You can also use the API directly in the browser via CDN:
179
113
 
180
- ### `configureApi(config)`
181
-
182
- | Parameter | Description | Required |
183
- |-----------|-------------|----------|
184
- | `apiUrl` | Chatbot API URL | โœ… Yes |
185
- | `apiKey` | API key for authentication | โœ… Yes |
186
- | `sessionId` | Session ID for tracking conversations | โŒ No |
187
-
188
- ---
189
-
190
- ## ๐Ÿ“ค Publish to npm
191
-
192
- **Build package:**
193
-
194
- ```bash
195
- npm run build
196
- ```
114
+ ```html
115
+ <script type="module">
116
+ import { configureApi, streamChat } from 'https://cdn.jsdelivr.net/npm/@schmitech/chatbot-api/dist/api.mjs';
197
117
 
198
- **Test locally (optional):**
118
+ configureApi({
119
+ apiUrl: 'https://your-api-server.com',
120
+ apiKey: 'your-api-key',
121
+ sessionId: 'your-session-id' // Optional
122
+ });
199
123
 
200
- ```bash
201
- npm pack --dry-run
124
+ async function handleChat() {
125
+ for await (const response of streamChat('Hello', true)) {
126
+ console.log(response.text);
127
+ }
128
+ }
129
+ </script>
202
130
  ```
203
131
 
204
- **Update version:**
132
+ ## ๐Ÿ“š API Reference
205
133
 
206
- ```bash
207
- npm version [patch|minor|major]
208
- ```
134
+ ### `configureApi(config)`
209
135
 
210
- **Publish:**
136
+ Configure the API client with server details.
211
137
 
212
- ```bash
213
- npm publish --access public
214
- ```
138
+ | Parameter | Type | Required | Description |
139
+ |-----------|------|----------|-------------|
140
+ | `apiUrl` | string | Yes | Chatbot API server URL |
141
+ | `apiKey` | string | Yes | API key for authentication |
142
+ | `sessionId` | string | No | Session ID for conversation tracking |
215
143
 
216
- ---
144
+ ### `streamChat(message: string, stream: boolean = true)`
217
145
 
218
- ## ๐Ÿ› ๏ธ Development
146
+ Stream chat responses from the server.
219
147
 
220
- ### ๐Ÿงช Testing
148
+ | Parameter | Type | Default | Description |
149
+ |-----------|------|---------|-------------|
150
+ | `message` | string | - | The message to send to the chat |
151
+ | `stream` | boolean | true | Whether to stream the response |
221
152
 
222
- ```bash
223
- # Test single query
224
- npm run test-query "your query" "http://your-api-server.com" "your-api-key" ["your-session-id"]
153
+ Returns an AsyncGenerator that yields `StreamResponse` objects:
225
154
 
226
- # Test multiple queries from JSON file
227
- npm run test-query-from-pairs questions.json "http://your-api-server.com" "your-api-key" [number_of_questions] ["your-session-id"]
155
+ ```typescript
156
+ interface StreamResponse {
157
+ text: string; // The text content of the response
158
+ done: boolean; // Whether this is the final response
159
+ }
228
160
  ```
229
161
 
230
- ---
231
-
232
- ## ๐Ÿ“ƒ License
162
+ ## ๐Ÿ”’ Security
233
163
 
234
- MIT License - See [LICENSE](LICENSE).
164
+ - Always use HTTPS for your API URL
165
+ - Keep your API key secure and never expose it in client-side code
166
+ - Consider using environment variables for sensitive configuration
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@schmitech/chatbot-api",
3
3
  "private": false,
4
- "version": "0.4.4",
4
+ "version": "0.4.5",
5
5
  "description": "API client for the ORBIT MCP server",
6
6
  "type": "module",
7
7
  "main": "./dist/api.cjs",