@schmitech/chatbot-api 0.4.0 โ 0.4.2
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 +52 -23
- package/api.d.ts +1 -1
- package/dist/api.cjs +2 -2
- package/dist/api.cjs.map +1 -1
- package/dist/api.mjs +122 -100
- package/dist/api.mjs.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# ๐ค Chatbot API Client
|
|
2
2
|
|
|
3
|
-
A JavaScript/TypeScript client for seamless interaction with the Chatbot server, now supporting API key authentication.
|
|
3
|
+
A JavaScript/TypeScript client for seamless interaction with the Chatbot server, now supporting API key authentication and session tracking.
|
|
4
4
|
|
|
5
5
|
---
|
|
6
6
|
|
|
@@ -37,7 +37,8 @@ Integrate directly into websites via CDN:
|
|
|
37
37
|
|
|
38
38
|
configureApi({
|
|
39
39
|
apiUrl: 'https://your-api-server.com',
|
|
40
|
-
apiKey: 'your-api-key'
|
|
40
|
+
apiKey: 'your-api-key',
|
|
41
|
+
sessionId: 'your-session-id' // Optional
|
|
41
42
|
});
|
|
42
43
|
|
|
43
44
|
async function handleChat() {
|
|
@@ -61,7 +62,8 @@ import { configureApi, streamChat } from '@schmitech/chatbot-api';
|
|
|
61
62
|
|
|
62
63
|
configureApi({
|
|
63
64
|
apiUrl: 'https://your-api-server.com',
|
|
64
|
-
apiKey: 'your-api-key'
|
|
65
|
+
apiKey: 'your-api-key',
|
|
66
|
+
sessionId: 'your-session-id' // Optional
|
|
65
67
|
});
|
|
66
68
|
```
|
|
67
69
|
|
|
@@ -69,7 +71,11 @@ configureApi({
|
|
|
69
71
|
|
|
70
72
|
```javascript
|
|
71
73
|
async function chat() {
|
|
72
|
-
configureApi({
|
|
74
|
+
configureApi({
|
|
75
|
+
apiUrl: 'https://your-api-server.com',
|
|
76
|
+
apiKey: 'your-api-key',
|
|
77
|
+
sessionId: 'user_123_session_456' // Optional
|
|
78
|
+
});
|
|
73
79
|
|
|
74
80
|
for await (const response of streamChat('Hello, how can I help?', false)) {
|
|
75
81
|
console.log(response.text);
|
|
@@ -84,7 +90,11 @@ chat();
|
|
|
84
90
|
|
|
85
91
|
```javascript
|
|
86
92
|
async function chatWithVoice() {
|
|
87
|
-
configureApi({
|
|
93
|
+
configureApi({
|
|
94
|
+
apiUrl: 'https://your-api-server.com',
|
|
95
|
+
apiKey: 'your-api-key',
|
|
96
|
+
sessionId: 'user_123_session_456' // Optional
|
|
97
|
+
});
|
|
88
98
|
|
|
89
99
|
for await (const response of streamChat('Tell me a joke', true)) {
|
|
90
100
|
if (response.type === 'audio') {
|
|
@@ -111,7 +121,8 @@ import { configureApi, streamChat } from '@schmitech/chatbot-api';
|
|
|
111
121
|
|
|
112
122
|
configureApi({
|
|
113
123
|
apiUrl: 'https://your-api-server.com',
|
|
114
|
-
apiKey: 'your-api-key'
|
|
124
|
+
apiKey: 'your-api-key',
|
|
125
|
+
sessionId: 'user_123_session_456' // Optional
|
|
115
126
|
});
|
|
116
127
|
|
|
117
128
|
function ChatComponent() {
|
|
@@ -149,7 +160,11 @@ export default ChatComponent;
|
|
|
149
160
|
### ๐ฒ React Native
|
|
150
161
|
|
|
151
162
|
```javascript
|
|
152
|
-
configureApi({
|
|
163
|
+
configureApi({
|
|
164
|
+
apiUrl: 'https://your-api-server.com',
|
|
165
|
+
apiKey: 'your-api-key',
|
|
166
|
+
sessionId: 'user_123_session_456' // Optional
|
|
167
|
+
});
|
|
153
168
|
|
|
154
169
|
async function handleChat(message) {
|
|
155
170
|
for await (const response of streamChat(message, false)) {
|
|
@@ -168,21 +183,34 @@ async function handleChat(message) {
|
|
|
168
183
|
|-----------|-------------|----------|
|
|
169
184
|
| `apiUrl` | Chatbot API URL | โ
Yes |
|
|
170
185
|
| `apiKey` | API key for authentication | โ
Yes |
|
|
186
|
+
| `sessionId` | Session ID for tracking conversations | โ No |
|
|
171
187
|
|
|
172
|
-
|
|
188
|
+
---
|
|
173
189
|
|
|
174
|
-
|
|
175
|
-
- `message`: Message string
|
|
176
|
-
- `voiceEnabled`: Boolean, enables audio response
|
|
190
|
+
## ๐ค Publish to npm
|
|
177
191
|
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
192
|
+
**Build package:**
|
|
193
|
+
|
|
194
|
+
```bash
|
|
195
|
+
npm run build
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
**Test locally (optional):**
|
|
199
|
+
|
|
200
|
+
```bash
|
|
201
|
+
npm pack --dry-run
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
**Update version:**
|
|
205
|
+
|
|
206
|
+
```bash
|
|
207
|
+
npm version [patch|minor|major]
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
**Publish:**
|
|
211
|
+
|
|
212
|
+
```bash
|
|
213
|
+
npm publish --access public
|
|
186
214
|
```
|
|
187
215
|
|
|
188
216
|
---
|
|
@@ -192,10 +220,11 @@ interface StreamResponse {
|
|
|
192
220
|
### ๐งช Testing
|
|
193
221
|
|
|
194
222
|
```bash
|
|
195
|
-
|
|
196
|
-
npm test
|
|
197
|
-
|
|
198
|
-
|
|
223
|
+
# Test single query
|
|
224
|
+
npm run test-query "your query" "http://your-api-server.com" "your-api-key" ["your-session-id"]
|
|
225
|
+
|
|
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"]
|
|
199
228
|
```
|
|
200
229
|
|
|
201
230
|
---
|
package/api.d.ts
CHANGED
|
@@ -25,7 +25,7 @@ interface MCPResponse {
|
|
|
25
25
|
message: string;
|
|
26
26
|
};
|
|
27
27
|
}
|
|
28
|
-
export declare const configureApi: (apiUrl: string, apiKey: string) => void;
|
|
28
|
+
export declare const configureApi: (apiUrl: string, apiKey: string, sessionId: string) => void;
|
|
29
29
|
export declare function streamChat(message: string, stream?: boolean): AsyncGenerator<StreamResponse>;
|
|
30
30
|
export declare function sendToolsRequest(tools: Array<{
|
|
31
31
|
name: string;
|
package/dist/api.cjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});let
|
|
2
|
-
`);a=N.pop()||"";for(const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});let m=null,A=null,P=null;const $=(t,e,r)=>{if(!t||typeof t!="string")throw new Error("API URL must be a valid string");if(!e||typeof e!="string")throw new Error("API key must be a valid string");if(!r||typeof r!="string")throw new Error("Session ID must be a valid string");m=t,A=e,P=r},D=()=>{if(!m)throw new Error("API URL not configured. Please call configureApi() with your server URL before using any API functions.");return m},q=()=>{if(!A)throw new Error("API key not configured. Please call configureApi() with your API key before using any API functions.");return A},L=()=>{if(!P)throw new Error("Session ID not configured. Please call configureApi() with your session ID before using any API functions.");return P},R=(t,e={})=>{t.startsWith("https:");const n={Connection:"keep-alive","X-Request-ID":Date.now().toString(36)+Math.random().toString(36).substring(2),"X-API-Key":q(),"X-Session-ID":L()};return{...e,headers:{...e.headers,...n}}},x=(t,e=!0)=>({jsonrpc:"2.0",method:"tools/call",params:{name:"chat",arguments:{messages:[{role:"user",content:t}],stream:e}},id:Date.now().toString(36)+Math.random().toString(36).substring(2)}),J=t=>({jsonrpc:"2.0",method:"tools/call",params:{name:"tools",arguments:{tools:t}},id:Date.now().toString(36)+Math.random().toString(36).substring(2)});async function*T(t,e=!0){var r,n,u,b,k,E,S,I,v;try{const i=D(),C=new AbortController,j=setTimeout(()=>C.abort(),1e4),l=await fetch(`${i}/v1/chat`,{...R(i,{method:"POST",headers:{"Content-Type":"application/json",Accept:e?"text/event-stream":"application/json"},body:JSON.stringify(x(t,e))}),signal:C.signal});if(clearTimeout(j),!l.ok){const o=await l.text();throw new Error(`Network response was not ok: ${l.status} ${o}`)}if(!e){const o=await l.json();if(o.error)throw new Error(`MCP Error: ${o.error.message}`);(b=(u=(n=(r=o.result)==null?void 0:r.output)==null?void 0:n.messages)==null?void 0:u[0])!=null&&b.content&&(yield{text:o.result.output.messages[0].content,done:!0});return}const p=(k=l.body)==null?void 0:k.getReader();if(!p)throw new Error("No reader available");const M=new TextDecoder;let a="",w="";try{for(;;){const{done:o,value:c}=await p.read();if(o)break;const f=M.decode(c,{stream:!0});a+=f;const N=a.split(`
|
|
2
|
+
`);a=N.pop()||"";for(const d of N)if(d.trim()&&d.startsWith("data: "))try{const h=d.slice(6).trim();if(h==="[DONE]"){yield{text:"",done:!0};break}const s=JSON.parse(h);if(s.result){let g="";if(s.result.type==="start")continue;if(s.result.type==="chunk"&&s.result.chunk?g=s.result.chunk.content:s.result.type==="complete"&&((S=(E=s.result.output)==null?void 0:E.messages)!=null&&S[0])&&(g=s.result.output.messages[0].content),g){const y=O(g,w);y?(w+=y,yield{text:y,done:s.result.type==="complete"}):s.result.type==="complete"&&(yield{text:"",done:!0})}}}catch(h){console.warn("Error parsing JSON chunk:",d,"Error:",h)}}}finally{p.releaseLock()}if(a&&a.startsWith("data: "))try{const o=a.slice(6).trim();if(o!=="[DONE]"){const c=JSON.parse(o);if((v=(I=c.result)==null?void 0:I.chunk)!=null&&v.content){const f=O(c.result.chunk.content,w);f&&(yield{text:f,done:c.result.type==="complete"})}}}catch(o){console.warn("Error parsing final JSON buffer:",a,"Error:",o)}}catch(i){i.name==="AbortError"?yield{text:"Connection timed out. Please check if the server is running.",done:!0}:i.name==="TypeError"&&i.message.includes("Failed to fetch")?yield{text:"Could not connect to the server. Please check if the server is running.",done:!0}:yield{text:`Error: ${i.message}`,done:!0}}}function O(t,e){if(!e)return t;if(e.endsWith(t))return"";if(t.length>e.length){if(t.startsWith(e))return t.slice(e.length);let r=0;const n=Math.min(e.length,t.length);for(;r<n&&e[r]===t[r];)r++;if(r>e.length/2)return t.slice(r)}return t}async function U(t){const e=D(),r=await fetch(`${e}/v1/chat`,R(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(J(t))}));if(!r.ok){const u=await r.text();throw new Error(`Network response was not ok: ${r.status} ${u}`)}const n=await r.json();if(n.error)throw new Error(`MCP Error: ${n.error.message}`);return n}exports.configureApi=$;exports.sendToolsRequest=U;exports.streamChat=T;
|
|
3
3
|
//# sourceMappingURL=api.cjs.map
|
package/dist/api.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.cjs","sources":["../api.ts"],"sourcesContent":["// For Node.js environments, we can use http.Agent for connection pooling\nlet httpAgent: any = null;\nlet httpsAgent: any = null;\n\n// Define the StreamResponse interface\nexport interface StreamResponse {\n text: string;\n done: boolean;\n}\n\nexport interface ChatResponse {\n response: string;\n}\n\n// MCP Protocol interfaces\ninterface MCPRequest {\n jsonrpc: \"2.0\";\n method: string;\n params: {\n name: string;\n arguments: {\n messages?: Array<{\n role: string;\n content: string;\n }>;\n stream?: boolean;\n tools?: Array<{\n name: string;\n parameters: Record<string, any>;\n }>;\n };\n };\n id: string;\n}\n\ninterface MCPResponse {\n jsonrpc: \"2.0\";\n id: string;\n result?: {\n type?: \"start\" | \"chunk\" | \"complete\";\n chunk?: {\n content: string;\n };\n output?: {\n messages: Array<{\n role: string;\n content: string;\n }>;\n };\n };\n error?: {\n code: number;\n message: string;\n };\n}\n\n// Store the configured API URL and key\nlet configuredApiUrl: string | null = null;\nlet configuredApiKey: string | null = null;\n\n// Configure the API with a custom URL and API key\nexport const configureApi = (apiUrl: string, apiKey: string): void => {\n if (!apiUrl || typeof apiUrl !== 'string') {\n throw new Error('API URL must be a valid string');\n }\n if (!apiKey || typeof apiKey !== 'string') {\n throw new Error('API key must be a valid string');\n }\n configuredApiUrl = apiUrl;\n configuredApiKey = apiKey;\n}\n\n// Get the configured API URL or throw an error if not configured\nconst getApiUrl = (): string => {\n if (!configuredApiUrl) {\n throw new Error('API URL not configured. Please call configureApi() with your server URL before using any API functions.');\n }\n return configuredApiUrl;\n};\n\n// Get the configured API key or throw an error if not configured\nconst getApiKey = (): string => {\n if (!configuredApiKey) {\n throw new Error('API key not configured. Please call configureApi() with your API key before using any API functions.');\n }\n return configuredApiKey;\n};\n\n// Helper to get fetch options with connection pooling if available\nconst getFetchOptions = (apiUrl: string, options: RequestInit = {}): RequestInit | any => {\n const isHttps = apiUrl.startsWith('https:');\n \n // Only use agents in Node.js environment\n if (typeof window === 'undefined') {\n if (isHttps && httpsAgent) {\n return { ...options, agent: httpsAgent } as any;\n } else if (httpAgent) {\n return { ...options, agent: httpAgent } as any;\n }\n }\n \n // Browser environment\n const requestId = Date.now().toString(36) + Math.random().toString(36).substring(2);\n \n // Use keep-alive header in browser environments\n return {\n ...options,\n headers: {\n ...options.headers,\n 'Connection': 'keep-alive',\n 'X-Request-ID': requestId,\n 'X-API-Key': getApiKey()\n }\n };\n};\n\n// Create MCP request\nconst createMCPRequest = (message: string, stream: boolean = true): MCPRequest => {\n return {\n jsonrpc: \"2.0\",\n method: \"tools/call\",\n params: {\n name: \"chat\",\n arguments: {\n messages: [\n { role: \"user\", content: message }\n ],\n stream\n }\n },\n id: Date.now().toString(36) + Math.random().toString(36).substring(2)\n };\n};\n\n// Create MCP tools request\nconst createMCPToolsRequest = (tools: Array<{ name: string; parameters: Record<string, any> }>): MCPRequest => {\n return {\n jsonrpc: \"2.0\",\n method: \"tools/call\",\n params: {\n name: \"tools\",\n arguments: {\n tools\n }\n },\n id: Date.now().toString(36) + Math.random().toString(36).substring(2)\n };\n};\n\nexport async function* streamChat(\n message: string,\n stream: boolean = true\n): AsyncGenerator<StreamResponse> {\n try {\n const API_URL = getApiUrl();\n \n const response = await fetch(`${API_URL}/v1/chat`, getFetchOptions(API_URL, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n 'Accept': stream ? 'text/event-stream' : 'application/json'\n },\n body: JSON.stringify(createMCPRequest(message, stream)),\n }));\n\n if (!response.ok) {\n const errorText = await response.text();\n console.error(`API request failed: ${response.status} ${errorText}`);\n throw new Error(`Network response was not ok: ${response.status} ${errorText}`);\n }\n\n if (!stream) {\n // Handle non-streaming response\n const data = await response.json() as MCPResponse;\n if (data.error) {\n throw new Error(`MCP Error: ${data.error.message}`);\n }\n if (data.result?.output?.messages?.[0]?.content) {\n yield {\n text: data.result.output.messages[0].content,\n done: true\n };\n }\n return;\n }\n \n const reader = response.body?.getReader();\n if (!reader) throw new Error('No reader available');\n\n const decoder = new TextDecoder();\n let buffer = '';\n let currentFullText = '';\n\n while (true) {\n const { done, value } = await reader.read();\n if (done) break;\n\n const chunk = decoder.decode(value, { stream: true });\n buffer += chunk;\n const lines = buffer.split('\\n');\n buffer = lines.pop() || '';\n\n for (const line of lines) {\n if (line.trim() && line.startsWith('data: ')) {\n try {\n const jsonText = line.slice(6).trim();\n if (jsonText === '[DONE]') {\n yield { text: '', done: true };\n break;\n }\n\n const data = JSON.parse(jsonText) as MCPResponse;\n \n if (data.result) {\n let content = '';\n \n // Handle different response types\n if (data.result.type === 'start') {\n continue;\n } else if (data.result.type === 'chunk' && data.result.chunk) {\n content = data.result.chunk.content;\n } else if (data.result.type === 'complete' && data.result.output?.messages?.[0]) {\n content = data.result.output.messages[0].content;\n }\n\n if (content) {\n const newText = extractNewText(content, currentFullText);\n if (newText) {\n currentFullText += newText;\n yield {\n text: newText,\n done: data.result.type === 'complete'\n };\n } else if (data.result.type === 'complete') {\n yield { text: '', done: true };\n }\n }\n }\n } catch (error) {\n console.warn('Error parsing JSON chunk:', line, 'Error:', error);\n }\n }\n }\n }\n\n // Handle any remaining buffer\n if (buffer && buffer.startsWith('data: ')) {\n try {\n const jsonText = buffer.slice(6).trim();\n if (jsonText !== '[DONE]') {\n const data = JSON.parse(jsonText) as MCPResponse;\n if (data.result?.chunk?.content) {\n const newText = extractNewText(data.result.chunk.content, currentFullText);\n if (newText) {\n yield {\n text: newText,\n done: data.result.type === 'complete'\n };\n }\n }\n }\n } catch (error) {\n console.warn('Error parsing final JSON buffer:', buffer, 'Error:', error);\n }\n }\n } catch (error: any) {\n console.error('Chat API error:', error.message);\n yield { \n text: `Error connecting to chat server: ${error.message}`, \n done: true \n };\n }\n}\n\n// Helper function to extract only new text from incoming chunks\nfunction extractNewText(incomingText: string, currentText: string): string {\n if (!currentText) return incomingText;\n if (currentText.endsWith(incomingText)) return '';\n \n if (incomingText.length > currentText.length) {\n if (incomingText.startsWith(currentText)) {\n return incomingText.slice(currentText.length);\n }\n \n let i = 0;\n const minLength = Math.min(currentText.length, incomingText.length);\n while (i < minLength && currentText[i] === incomingText[i]) {\n i++;\n }\n \n if (i > currentText.length / 2) {\n return incomingText.slice(i);\n }\n }\n \n return incomingText;\n}\n\n// New function to send tools request\nexport async function sendToolsRequest(tools: Array<{ name: string; parameters: Record<string, any> }>): Promise<MCPResponse> {\n const API_URL = getApiUrl();\n \n const response = await fetch(`${API_URL}/v1/chat`, getFetchOptions(API_URL, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json'\n },\n body: JSON.stringify(createMCPToolsRequest(tools)),\n }));\n\n if (!response.ok) {\n const errorText = await response.text();\n throw new Error(`Network response was not ok: ${response.status} ${errorText}`);\n }\n\n const data = await response.json() as MCPResponse;\n if (data.error) {\n throw new Error(`MCP Error: ${data.error.message}`);\n }\n\n return data;\n}"],"names":["configuredApiUrl","configuredApiKey","configureApi","apiUrl","apiKey","getApiUrl","getApiKey","getFetchOptions","options","requestId","createMCPRequest","message","stream","createMCPToolsRequest","tools","streamChat","API_URL","response","errorText","data","_d","_c","_b","_a","reader","_e","decoder","buffer","currentFullText","done","value","chunk","lines","line","jsonText","content","_g","_f","newText","extractNewText","error","_i","_h","incomingText","currentText","i","minLength","sendToolsRequest"],"mappings":"gFAyDA,IAAIA,EAAkC,KAClCC,EAAkC,KAGzB,MAAAC,EAAe,CAACC,EAAgBC,IAAyB,CACpE,GAAI,CAACD,GAAU,OAAOA,GAAW,SACzB,MAAA,IAAI,MAAM,gCAAgC,EAElD,GAAI,CAACC,GAAU,OAAOA,GAA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AAM,EACR,CAAA,CAEJ,CAGA,SAASD,EAAeI,EAAsBC,EAA6B,CACrE,GAAA,CAACA,EAAoB,OAAAD,EACzB,GAAIC,EAAY,SAASD,CAAY,EAAU,MAAA,GAE3C,GAAAA,EAAa,OAASC,EAAY,OAAQ,CACxC,GAAAD,EAAa,WAAWC,CAAW,EAC9B,OAAAD,EAAa,MAAMC,EAAY,MAAM,EAG9C,IAAIC,EAAI,EACR,MAAMC,EAAY,KAAK,IAAIF,EAAY,OAAQD,EAAa,MAAM,EAClE,KAAOE,EAAIC,GAAaF,EAAYC,CAAC,IAAMF,EAAaE,CAAC,GACvDA,IAGE,GAAAA,EAAID,EAAY,OAAS,EACpB,OAAAD,EAAa,MAAME,CAAC,CAC7B,CAGK,OAAAF,CACT,CAGA,eAAsBI,EAAiBjC,EAAuF,CAC5H,MAAME,EAAUX,EAAU,EAEpBY,EAAW,MAAM,MAAM,GAAGD,CAAO,WAAYT,EAAgBS,EAAS,CAC1E,OAAQ,OACR,QAAS,CACP,eAAgB,kBAClB,EACA,KAAM,KAAK,UAAUH,EAAsBC,CAAK,CAAC,CAAA,CAClD,CAAC,EAEE,GAAA,CAACG,EAAS,GAAI,CACV,MAAAC,EAAY,MAAMD,EAAS,KAAK,EACtC,MAAM,IAAI,MAAM,gCAAgCA,EAAS,MAAM,IAAIC,CAAS,EAAE,CAAA,CAG1E,MAAAC,EAAO,MAAMF,EAAS,KAAK,EACjC,GAAIE,EAAK,MACP,MAAM,IAAI,MAAM,cAAcA,EAAK,MAAM,OAAO,EAAE,EAG7C,OAAAA,CACT"}
|
|
1
|
+
{"version":3,"file":"api.cjs","sources":["../api.ts"],"sourcesContent":["// For Node.js environments, we can use http.Agent for connection pooling\nlet httpAgent: any = null;\nlet httpsAgent: any = null;\n\n// Define the StreamResponse interface\nexport interface StreamResponse {\n text: string;\n done: boolean;\n}\n\nexport interface ChatResponse {\n response: string;\n}\n\n// MCP Protocol interfaces\ninterface MCPRequest {\n jsonrpc: \"2.0\";\n method: string;\n params: {\n name: string;\n arguments: {\n messages?: Array<{\n role: string;\n content: string;\n }>;\n stream?: boolean;\n tools?: Array<{\n name: string;\n parameters: Record<string, any>;\n }>;\n };\n };\n id: string;\n}\n\ninterface MCPResponse {\n jsonrpc: \"2.0\";\n id: string;\n result?: {\n type?: \"start\" | \"chunk\" | \"complete\";\n chunk?: {\n content: string;\n };\n output?: {\n messages: Array<{\n role: string;\n content: string;\n }>;\n };\n };\n error?: {\n code: number;\n message: string;\n };\n}\n\n// Store the configured API URL, key, and session ID\nlet configuredApiUrl: string | null = null;\nlet configuredApiKey: string | null = null;\nlet configuredSessionId: string | null = null;\n\n// Configure the API with a custom URL, API key, and session ID\nexport const configureApi = (apiUrl: string, apiKey: string, sessionId: string): void => {\n if (!apiUrl || typeof apiUrl !== 'string') {\n throw new Error('API URL must be a valid string');\n }\n if (!apiKey || typeof apiKey !== 'string') {\n throw new Error('API key must be a valid string');\n }\n if (!sessionId || typeof sessionId !== 'string') {\n throw new Error('Session ID must be a valid string');\n }\n configuredApiUrl = apiUrl;\n configuredApiKey = apiKey;\n configuredSessionId = sessionId;\n}\n\n// Get the configured API URL or throw an error if not configured\nconst getApiUrl = (): string => {\n if (!configuredApiUrl) {\n throw new Error('API URL not configured. Please call configureApi() with your server URL before using any API functions.');\n }\n return configuredApiUrl;\n};\n\n// Get the configured API key or throw an error if not configured\nconst getApiKey = (): string => {\n if (!configuredApiKey) {\n throw new Error('API key not configured. Please call configureApi() with your API key before using any API functions.');\n }\n return configuredApiKey;\n};\n\n// Get the configured session ID or throw an error if not configured\nconst getSessionId = (): string => {\n if (!configuredSessionId) {\n throw new Error('Session ID not configured. Please call configureApi() with your session ID before using any API functions.');\n }\n return configuredSessionId;\n};\n\n// Helper to get fetch options with connection pooling if available\nconst getFetchOptions = (apiUrl: string, options: RequestInit = {}): RequestInit | any => {\n const isHttps = apiUrl.startsWith('https:');\n \n // Only use agents in Node.js environment\n if (typeof window === 'undefined') {\n if (isHttps && httpsAgent) {\n return { ...options, agent: httpsAgent } as any;\n } else if (httpAgent) {\n return { ...options, agent: httpAgent } as any;\n }\n }\n \n // Browser environment\n const requestId = Date.now().toString(36) + Math.random().toString(36).substring(2);\n \n // Use keep-alive header in browser environments\n const headers: Record<string, string> = {\n 'Connection': 'keep-alive',\n 'X-Request-ID': requestId,\n 'X-API-Key': getApiKey(),\n 'X-Session-ID': getSessionId()\n };\n \n return {\n ...options,\n headers: {\n ...options.headers,\n ...headers\n }\n };\n};\n\n// Create MCP request\nconst createMCPRequest = (message: string, stream: boolean = true): MCPRequest => {\n return {\n jsonrpc: \"2.0\",\n method: \"tools/call\",\n params: {\n name: \"chat\",\n arguments: {\n messages: [\n { role: \"user\", content: message }\n ],\n stream\n }\n },\n id: Date.now().toString(36) + Math.random().toString(36).substring(2)\n };\n};\n\n// Create MCP tools request\nconst createMCPToolsRequest = (tools: Array<{ name: string; parameters: Record<string, any> }>): MCPRequest => {\n return {\n jsonrpc: \"2.0\",\n method: \"tools/call\",\n params: {\n name: \"tools\",\n arguments: {\n tools\n }\n },\n id: Date.now().toString(36) + Math.random().toString(36).substring(2)\n };\n};\n\nexport async function* streamChat(\n message: string,\n stream: boolean = true\n): AsyncGenerator<StreamResponse> {\n try {\n const API_URL = getApiUrl();\n \n // Add timeout to the fetch request\n const controller = new AbortController();\n const timeoutId = setTimeout(() => controller.abort(), 10000); // 10 second timeout\n\n const response = await fetch(`${API_URL}/v1/chat`, {\n ...getFetchOptions(API_URL, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n 'Accept': stream ? 'text/event-stream' : 'application/json'\n },\n body: JSON.stringify(createMCPRequest(message, stream)),\n }),\n signal: controller.signal\n });\n\n clearTimeout(timeoutId);\n\n if (!response.ok) {\n const errorText = await response.text();\n throw new Error(`Network response was not ok: ${response.status} ${errorText}`);\n }\n\n if (!stream) {\n // Handle non-streaming response\n const data = await response.json() as MCPResponse;\n if (data.error) {\n throw new Error(`MCP Error: ${data.error.message}`);\n }\n if (data.result?.output?.messages?.[0]?.content) {\n yield {\n text: data.result.output.messages[0].content,\n done: true\n };\n }\n return;\n }\n \n const reader = response.body?.getReader();\n if (!reader) throw new Error('No reader available');\n\n const decoder = new TextDecoder();\n let buffer = '';\n let currentFullText = '';\n\n try {\n while (true) {\n const { done, value } = await reader.read();\n if (done) break;\n\n const chunk = decoder.decode(value, { stream: true });\n buffer += chunk;\n const lines = buffer.split('\\n');\n buffer = lines.pop() || '';\n\n for (const line of lines) {\n if (line.trim() && line.startsWith('data: ')) {\n try {\n const jsonText = line.slice(6).trim();\n if (jsonText === '[DONE]') {\n yield { text: '', done: true };\n break;\n }\n\n const data = JSON.parse(jsonText) as MCPResponse;\n \n if (data.result) {\n let content = '';\n \n if (data.result.type === 'start') {\n continue;\n } else if (data.result.type === 'chunk' && data.result.chunk) {\n content = data.result.chunk.content;\n } else if (data.result.type === 'complete' && data.result.output?.messages?.[0]) {\n content = data.result.output.messages[0].content;\n }\n\n if (content) {\n const newText = extractNewText(content, currentFullText);\n if (newText) {\n currentFullText += newText;\n yield {\n text: newText,\n done: data.result.type === 'complete'\n };\n } else if (data.result.type === 'complete') {\n yield { text: '', done: true };\n }\n }\n }\n } catch (error) {\n console.warn('Error parsing JSON chunk:', line, 'Error:', error);\n }\n }\n }\n }\n } finally {\n reader.releaseLock();\n }\n\n // Handle any remaining buffer\n if (buffer && buffer.startsWith('data: ')) {\n try {\n const jsonText = buffer.slice(6).trim();\n if (jsonText !== '[DONE]') {\n const data = JSON.parse(jsonText) as MCPResponse;\n if (data.result?.chunk?.content) {\n const newText = extractNewText(data.result.chunk.content, currentFullText);\n if (newText) {\n yield {\n text: newText,\n done: data.result.type === 'complete'\n };\n }\n }\n }\n } catch (error) {\n console.warn('Error parsing final JSON buffer:', buffer, 'Error:', error);\n }\n }\n } catch (error: any) {\n if (error.name === 'AbortError') {\n yield { \n text: 'Connection timed out. Please check if the server is running.', \n done: true \n };\n } else if (error.name === 'TypeError' && error.message.includes('Failed to fetch')) {\n yield { \n text: 'Could not connect to the server. Please check if the server is running.', \n done: true \n };\n } else {\n yield { \n text: `Error: ${error.message}`, \n done: true \n };\n }\n }\n}\n\n// Helper function to extract only new text from incoming chunks\nfunction extractNewText(incomingText: string, currentText: string): string {\n if (!currentText) return incomingText;\n if (currentText.endsWith(incomingText)) return '';\n \n if (incomingText.length > currentText.length) {\n if (incomingText.startsWith(currentText)) {\n return incomingText.slice(currentText.length);\n }\n \n let i = 0;\n const minLength = Math.min(currentText.length, incomingText.length);\n while (i < minLength && currentText[i] === incomingText[i]) {\n i++;\n }\n \n if (i > currentText.length / 2) {\n return incomingText.slice(i);\n }\n }\n \n return incomingText;\n}\n\n// New function to send tools request\nexport async function sendToolsRequest(tools: Array<{ name: string; parameters: Record<string, any> }>): Promise<MCPResponse> {\n const API_URL = getApiUrl();\n \n const response = await fetch(`${API_URL}/v1/chat`, getFetchOptions(API_URL, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json'\n },\n body: JSON.stringify(createMCPToolsRequest(tools)),\n }));\n\n if (!response.ok) {\n const errorText = await response.text();\n throw new Error(`Network response was not ok: ${response.status} ${errorText}`);\n }\n\n const data = await response.json() as MCPResponse;\n if (data.error) {\n throw new Error(`MCP Error: ${data.error.message}`);\n }\n\n return data;\n}"],"names":["configuredApiUrl","configuredApiKey","configuredSessionId","configureApi","apiUrl","apiKey","sessionId","getApiUrl","getApiKey","getSessionId","getFetchOptions","options","headers","createMCPRequest","message","stream","createMCPToolsRequest","tools","streamChat","API_URL","controller","timeoutId","response","errorText","data","_d","_c","_b","_a","reader","_e","decoder","buffer","currentFullText","done","value","chunk","lines","line","jsonText","content","_g","_f","newText","extractNewText","error","_i","_h","incomingText","currentText","i","minLength","sendToolsRequest"],"mappings":"gFAyDA,IAAIA,EAAkC,KAClCC,EAAkC,KAClCC,EAAqC,KAGlC,MAAMC,EAAe,CAACC,EAAgBC,EAAgBC,IAA4B,CACvF,GAAI,CAACF,GAAU,OAAOA,GAAW,SACzB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AAS,GAAI,CACV,MAAAC,EAAY,MAAMD,EAAS,KAAK,EACtC,MAAM,IAAI,MAAM,gCAAgCA,EAAS,MAAM,IAAIC,CAAS,EAAE,CAAA,CAG1E,MAAAC,EAAO,MAAMF,EAAS,KAAK,EACjC,GAAIE,EAAK,MACP,MAAM,IAAI,MAAM,cAAcA,EAAK,MAAM,OAAO,EAAE,EAG7C,OAAAA,CACT"}
|
package/dist/api.mjs
CHANGED
|
@@ -1,174 +1,196 @@
|
|
|
1
|
-
let
|
|
2
|
-
const
|
|
3
|
-
if (!e || typeof e != "string")
|
|
4
|
-
throw new Error("API URL must be a valid string");
|
|
1
|
+
let m = null, k = null, A = null;
|
|
2
|
+
const J = (t, e, r) => {
|
|
5
3
|
if (!t || typeof t != "string")
|
|
4
|
+
throw new Error("API URL must be a valid string");
|
|
5
|
+
if (!e || typeof e != "string")
|
|
6
6
|
throw new Error("API key must be a valid string");
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
return y;
|
|
12
|
-
}, j = () => {
|
|
7
|
+
if (!r || typeof r != "string")
|
|
8
|
+
throw new Error("Session ID must be a valid string");
|
|
9
|
+
m = t, k = e, A = r;
|
|
10
|
+
}, O = () => {
|
|
13
11
|
if (!m)
|
|
14
|
-
throw new Error("API
|
|
12
|
+
throw new Error("API URL not configured. Please call configureApi() with your server URL before using any API functions.");
|
|
15
13
|
return m;
|
|
16
|
-
},
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
}, M = () => {
|
|
15
|
+
if (!k)
|
|
16
|
+
throw new Error("API key not configured. Please call configureApi() with your API key before using any API functions.");
|
|
17
|
+
return k;
|
|
18
|
+
}, x = () => {
|
|
19
|
+
if (!A)
|
|
20
|
+
throw new Error("Session ID not configured. Please call configureApi() with your session ID before using any API functions.");
|
|
21
|
+
return A;
|
|
22
|
+
}, R = (t, e = {}) => {
|
|
23
|
+
t.startsWith("https:");
|
|
24
|
+
const n = {
|
|
25
|
+
Connection: "keep-alive",
|
|
26
|
+
"X-Request-ID": Date.now().toString(36) + Math.random().toString(36).substring(2),
|
|
27
|
+
"X-API-Key": M(),
|
|
28
|
+
"X-Session-ID": x()
|
|
29
|
+
};
|
|
19
30
|
return {
|
|
20
|
-
...
|
|
31
|
+
...e,
|
|
21
32
|
headers: {
|
|
22
|
-
...
|
|
23
|
-
|
|
24
|
-
"X-Request-ID": r,
|
|
25
|
-
"X-API-Key": j()
|
|
33
|
+
...e.headers,
|
|
34
|
+
...n
|
|
26
35
|
}
|
|
27
36
|
};
|
|
28
|
-
},
|
|
37
|
+
}, L = (t, e = !0) => ({
|
|
29
38
|
jsonrpc: "2.0",
|
|
30
39
|
method: "tools/call",
|
|
31
40
|
params: {
|
|
32
41
|
name: "chat",
|
|
33
42
|
arguments: {
|
|
34
43
|
messages: [
|
|
35
|
-
{ role: "user", content:
|
|
44
|
+
{ role: "user", content: t }
|
|
36
45
|
],
|
|
37
|
-
stream:
|
|
46
|
+
stream: e
|
|
38
47
|
}
|
|
39
48
|
},
|
|
40
49
|
id: Date.now().toString(36) + Math.random().toString(36).substring(2)
|
|
41
|
-
}),
|
|
50
|
+
}), q = (t) => ({
|
|
42
51
|
jsonrpc: "2.0",
|
|
43
52
|
method: "tools/call",
|
|
44
53
|
params: {
|
|
45
54
|
name: "tools",
|
|
46
55
|
arguments: {
|
|
47
|
-
tools:
|
|
56
|
+
tools: t
|
|
48
57
|
}
|
|
49
58
|
},
|
|
50
59
|
id: Date.now().toString(36) + Math.random().toString(36).substring(2)
|
|
51
60
|
});
|
|
52
|
-
async function*
|
|
53
|
-
var r,
|
|
61
|
+
async function* U(t, e = !0) {
|
|
62
|
+
var r, n, u, E, P, b, I, S, v;
|
|
54
63
|
try {
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
64
|
+
const i = O(), N = new AbortController(), j = setTimeout(() => N.abort(), 1e4), l = await fetch(`${i}/v1/chat`, {
|
|
65
|
+
...R(i, {
|
|
66
|
+
method: "POST",
|
|
67
|
+
headers: {
|
|
68
|
+
"Content-Type": "application/json",
|
|
69
|
+
Accept: e ? "text/event-stream" : "application/json"
|
|
70
|
+
},
|
|
71
|
+
body: JSON.stringify(L(t, e))
|
|
72
|
+
}),
|
|
73
|
+
signal: N.signal
|
|
74
|
+
});
|
|
75
|
+
if (clearTimeout(j), !l.ok) {
|
|
76
|
+
const o = await l.text();
|
|
77
|
+
throw new Error(`Network response was not ok: ${l.status} ${o}`);
|
|
66
78
|
}
|
|
67
|
-
if (!
|
|
68
|
-
const o = await
|
|
79
|
+
if (!e) {
|
|
80
|
+
const o = await l.json();
|
|
69
81
|
if (o.error)
|
|
70
82
|
throw new Error(`MCP Error: ${o.error.message}`);
|
|
71
|
-
(
|
|
83
|
+
(E = (u = (n = (r = o.result) == null ? void 0 : r.output) == null ? void 0 : n.messages) == null ? void 0 : u[0]) != null && E.content && (yield {
|
|
72
84
|
text: o.result.output.messages[0].content,
|
|
73
85
|
done: !0
|
|
74
86
|
});
|
|
75
87
|
return;
|
|
76
88
|
}
|
|
77
|
-
const
|
|
78
|
-
if (!
|
|
79
|
-
const
|
|
89
|
+
const p = (P = l.body) == null ? void 0 : P.getReader();
|
|
90
|
+
if (!p) throw new Error("No reader available");
|
|
91
|
+
const $ = new TextDecoder();
|
|
80
92
|
let a = "", w = "";
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
93
|
+
try {
|
|
94
|
+
for (; ; ) {
|
|
95
|
+
const { done: o, value: c } = await p.read();
|
|
96
|
+
if (o) break;
|
|
97
|
+
const f = $.decode(c, { stream: !0 });
|
|
98
|
+
a += f;
|
|
99
|
+
const C = a.split(`
|
|
87
100
|
`);
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
}
|
|
97
|
-
const n = JSON.parse(d);
|
|
98
|
-
if (n.result) {
|
|
99
|
-
let p = "";
|
|
100
|
-
if (n.result.type === "start")
|
|
101
|
-
continue;
|
|
102
|
-
if (n.result.type === "chunk" && n.result.chunk ? p = n.result.chunk.content : n.result.type === "complete" && ((E = (k = n.result.output) == null ? void 0 : k.messages) != null && E[0]) && (p = n.result.output.messages[0].content), p) {
|
|
103
|
-
const g = O(p, w);
|
|
104
|
-
g ? (w += g, yield {
|
|
105
|
-
text: g,
|
|
106
|
-
done: n.result.type === "complete"
|
|
107
|
-
}) : n.result.type === "complete" && (yield { text: "", done: !0 });
|
|
101
|
+
a = C.pop() || "";
|
|
102
|
+
for (const d of C)
|
|
103
|
+
if (d.trim() && d.startsWith("data: "))
|
|
104
|
+
try {
|
|
105
|
+
const h = d.slice(6).trim();
|
|
106
|
+
if (h === "[DONE]") {
|
|
107
|
+
yield { text: "", done: !0 };
|
|
108
|
+
break;
|
|
108
109
|
}
|
|
110
|
+
const s = JSON.parse(h);
|
|
111
|
+
if (s.result) {
|
|
112
|
+
let g = "";
|
|
113
|
+
if (s.result.type === "start")
|
|
114
|
+
continue;
|
|
115
|
+
if (s.result.type === "chunk" && s.result.chunk ? g = s.result.chunk.content : s.result.type === "complete" && ((I = (b = s.result.output) == null ? void 0 : b.messages) != null && I[0]) && (g = s.result.output.messages[0].content), g) {
|
|
116
|
+
const y = D(g, w);
|
|
117
|
+
y ? (w += y, yield {
|
|
118
|
+
text: y,
|
|
119
|
+
done: s.result.type === "complete"
|
|
120
|
+
}) : s.result.type === "complete" && (yield { text: "", done: !0 });
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
} catch (h) {
|
|
124
|
+
console.warn("Error parsing JSON chunk:", d, "Error:", h);
|
|
109
125
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
126
|
+
}
|
|
127
|
+
} finally {
|
|
128
|
+
p.releaseLock();
|
|
113
129
|
}
|
|
114
130
|
if (a && a.startsWith("data: "))
|
|
115
131
|
try {
|
|
116
132
|
const o = a.slice(6).trim();
|
|
117
133
|
if (o !== "[DONE]") {
|
|
118
|
-
const
|
|
119
|
-
if ((
|
|
120
|
-
const f =
|
|
134
|
+
const c = JSON.parse(o);
|
|
135
|
+
if ((v = (S = c.result) == null ? void 0 : S.chunk) != null && v.content) {
|
|
136
|
+
const f = D(c.result.chunk.content, w);
|
|
121
137
|
f && (yield {
|
|
122
138
|
text: f,
|
|
123
|
-
done:
|
|
139
|
+
done: c.result.type === "complete"
|
|
124
140
|
});
|
|
125
141
|
}
|
|
126
142
|
}
|
|
127
143
|
} catch (o) {
|
|
128
144
|
console.warn("Error parsing final JSON buffer:", a, "Error:", o);
|
|
129
145
|
}
|
|
130
|
-
} catch (
|
|
131
|
-
|
|
132
|
-
text:
|
|
146
|
+
} catch (i) {
|
|
147
|
+
i.name === "AbortError" ? yield {
|
|
148
|
+
text: "Connection timed out. Please check if the server is running.",
|
|
149
|
+
done: !0
|
|
150
|
+
} : i.name === "TypeError" && i.message.includes("Failed to fetch") ? yield {
|
|
151
|
+
text: "Could not connect to the server. Please check if the server is running.",
|
|
152
|
+
done: !0
|
|
153
|
+
} : yield {
|
|
154
|
+
text: `Error: ${i.message}`,
|
|
133
155
|
done: !0
|
|
134
156
|
};
|
|
135
157
|
}
|
|
136
158
|
}
|
|
137
|
-
function
|
|
138
|
-
if (!
|
|
139
|
-
if (
|
|
140
|
-
if (
|
|
141
|
-
if (
|
|
142
|
-
return
|
|
159
|
+
function D(t, e) {
|
|
160
|
+
if (!e) return t;
|
|
161
|
+
if (e.endsWith(t)) return "";
|
|
162
|
+
if (t.length > e.length) {
|
|
163
|
+
if (t.startsWith(e))
|
|
164
|
+
return t.slice(e.length);
|
|
143
165
|
let r = 0;
|
|
144
|
-
const
|
|
145
|
-
for (; r <
|
|
166
|
+
const n = Math.min(e.length, t.length);
|
|
167
|
+
for (; r < n && e[r] === t[r]; )
|
|
146
168
|
r++;
|
|
147
|
-
if (r >
|
|
148
|
-
return
|
|
169
|
+
if (r > e.length / 2)
|
|
170
|
+
return t.slice(r);
|
|
149
171
|
}
|
|
150
|
-
return
|
|
172
|
+
return t;
|
|
151
173
|
}
|
|
152
|
-
async function
|
|
153
|
-
const
|
|
174
|
+
async function W(t) {
|
|
175
|
+
const e = O(), r = await fetch(`${e}/v1/chat`, R(e, {
|
|
154
176
|
method: "POST",
|
|
155
177
|
headers: {
|
|
156
178
|
"Content-Type": "application/json"
|
|
157
179
|
},
|
|
158
|
-
body: JSON.stringify(
|
|
180
|
+
body: JSON.stringify(q(t))
|
|
159
181
|
}));
|
|
160
182
|
if (!r.ok) {
|
|
161
183
|
const u = await r.text();
|
|
162
184
|
throw new Error(`Network response was not ok: ${r.status} ${u}`);
|
|
163
185
|
}
|
|
164
|
-
const
|
|
165
|
-
if (
|
|
166
|
-
throw new Error(`MCP Error: ${
|
|
167
|
-
return
|
|
186
|
+
const n = await r.json();
|
|
187
|
+
if (n.error)
|
|
188
|
+
throw new Error(`MCP Error: ${n.error.message}`);
|
|
189
|
+
return n;
|
|
168
190
|
}
|
|
169
191
|
export {
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
192
|
+
J as configureApi,
|
|
193
|
+
W as sendToolsRequest,
|
|
194
|
+
U as streamChat
|
|
173
195
|
};
|
|
174
196
|
//# sourceMappingURL=api.mjs.map
|
package/dist/api.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.mjs","sources":["../api.ts"],"sourcesContent":["// For Node.js environments, we can use http.Agent for connection pooling\nlet httpAgent: any = null;\nlet httpsAgent: any = null;\n\n// Define the StreamResponse interface\nexport interface StreamResponse {\n text: string;\n done: boolean;\n}\n\nexport interface ChatResponse {\n response: string;\n}\n\n// MCP Protocol interfaces\ninterface MCPRequest {\n jsonrpc: \"2.0\";\n method: string;\n params: {\n name: string;\n arguments: {\n messages?: Array<{\n role: string;\n content: string;\n }>;\n stream?: boolean;\n tools?: Array<{\n name: string;\n parameters: Record<string, any>;\n }>;\n };\n };\n id: string;\n}\n\ninterface MCPResponse {\n jsonrpc: \"2.0\";\n id: string;\n result?: {\n type?: \"start\" | \"chunk\" | \"complete\";\n chunk?: {\n content: string;\n };\n output?: {\n messages: Array<{\n role: string;\n content: string;\n }>;\n };\n };\n error?: {\n code: number;\n message: string;\n };\n}\n\n// Store the configured API URL and key\nlet configuredApiUrl: string | null = null;\nlet configuredApiKey: string | null = null;\n\n// Configure the API with a custom URL and API key\nexport const configureApi = (apiUrl: string, apiKey: string): void => {\n if (!apiUrl || typeof apiUrl !== 'string') {\n throw new Error('API URL must be a valid string');\n }\n if (!apiKey || typeof apiKey !== 'string') {\n throw new Error('API key must be a valid string');\n }\n configuredApiUrl = apiUrl;\n configuredApiKey = apiKey;\n}\n\n// Get the configured API URL or throw an error if not configured\nconst getApiUrl = (): string => {\n if (!configuredApiUrl) {\n throw new Error('API URL not configured. Please call configureApi() with your server URL before using any API functions.');\n }\n return configuredApiUrl;\n};\n\n// Get the configured API key or throw an error if not configured\nconst getApiKey = (): string => {\n if (!configuredApiKey) {\n throw new Error('API key not configured. Please call configureApi() with your API key before using any API functions.');\n }\n return configuredApiKey;\n};\n\n// Helper to get fetch options with connection pooling if available\nconst getFetchOptions = (apiUrl: string, options: RequestInit = {}): RequestInit | any => {\n const isHttps = apiUrl.startsWith('https:');\n \n // Only use agents in Node.js environment\n if (typeof window === 'undefined') {\n if (isHttps && httpsAgent) {\n return { ...options, agent: httpsAgent } as any;\n } else if (httpAgent) {\n return { ...options, agent: httpAgent } as any;\n }\n }\n \n // Browser environment\n const requestId = Date.now().toString(36) + Math.random().toString(36).substring(2);\n \n // Use keep-alive header in browser environments\n return {\n ...options,\n headers: {\n ...options.headers,\n 'Connection': 'keep-alive',\n 'X-Request-ID': requestId,\n 'X-API-Key': getApiKey()\n }\n };\n};\n\n// Create MCP request\nconst createMCPRequest = (message: string, stream: boolean = true): MCPRequest => {\n return {\n jsonrpc: \"2.0\",\n method: \"tools/call\",\n params: {\n name: \"chat\",\n arguments: {\n messages: [\n { role: \"user\", content: message }\n ],\n stream\n }\n },\n id: Date.now().toString(36) + Math.random().toString(36).substring(2)\n };\n};\n\n// Create MCP tools request\nconst createMCPToolsRequest = (tools: Array<{ name: string; parameters: Record<string, any> }>): MCPRequest => {\n return {\n jsonrpc: \"2.0\",\n method: \"tools/call\",\n params: {\n name: \"tools\",\n arguments: {\n tools\n }\n },\n id: Date.now().toString(36) + Math.random().toString(36).substring(2)\n };\n};\n\nexport async function* streamChat(\n message: string,\n stream: boolean = true\n): AsyncGenerator<StreamResponse> {\n try {\n const API_URL = getApiUrl();\n \n const response = await fetch(`${API_URL}/v1/chat`, getFetchOptions(API_URL, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n 'Accept': stream ? 'text/event-stream' : 'application/json'\n },\n body: JSON.stringify(createMCPRequest(message, stream)),\n }));\n\n if (!response.ok) {\n const errorText = await response.text();\n console.error(`API request failed: ${response.status} ${errorText}`);\n throw new Error(`Network response was not ok: ${response.status} ${errorText}`);\n }\n\n if (!stream) {\n // Handle non-streaming response\n const data = await response.json() as MCPResponse;\n if (data.error) {\n throw new Error(`MCP Error: ${data.error.message}`);\n }\n if (data.result?.output?.messages?.[0]?.content) {\n yield {\n text: data.result.output.messages[0].content,\n done: true\n };\n }\n return;\n }\n \n const reader = response.body?.getReader();\n if (!reader) throw new Error('No reader available');\n\n const decoder = new TextDecoder();\n let buffer = '';\n let currentFullText = '';\n\n while (true) {\n const { done, value } = await reader.read();\n if (done) break;\n\n const chunk = decoder.decode(value, { stream: true });\n buffer += chunk;\n const lines = buffer.split('\\n');\n buffer = lines.pop() || '';\n\n for (const line of lines) {\n if (line.trim() && line.startsWith('data: ')) {\n try {\n const jsonText = line.slice(6).trim();\n if (jsonText === '[DONE]') {\n yield { text: '', done: true };\n break;\n }\n\n const data = JSON.parse(jsonText) as MCPResponse;\n \n if (data.result) {\n let content = '';\n \n // Handle different response types\n if (data.result.type === 'start') {\n continue;\n } else if (data.result.type === 'chunk' && data.result.chunk) {\n content = data.result.chunk.content;\n } else if (data.result.type === 'complete' && data.result.output?.messages?.[0]) {\n content = data.result.output.messages[0].content;\n }\n\n if (content) {\n const newText = extractNewText(content, currentFullText);\n if (newText) {\n currentFullText += newText;\n yield {\n text: newText,\n done: data.result.type === 'complete'\n };\n } else if (data.result.type === 'complete') {\n yield { text: '', done: true };\n }\n }\n }\n } catch (error) {\n console.warn('Error parsing JSON chunk:', line, 'Error:', error);\n }\n }\n }\n }\n\n // Handle any remaining buffer\n if (buffer && buffer.startsWith('data: ')) {\n try {\n const jsonText = buffer.slice(6).trim();\n if (jsonText !== '[DONE]') {\n const data = JSON.parse(jsonText) as MCPResponse;\n if (data.result?.chunk?.content) {\n const newText = extractNewText(data.result.chunk.content, currentFullText);\n if (newText) {\n yield {\n text: newText,\n done: data.result.type === 'complete'\n };\n }\n }\n }\n } catch (error) {\n console.warn('Error parsing final JSON buffer:', buffer, 'Error:', error);\n }\n }\n } catch (error: any) {\n console.error('Chat API error:', error.message);\n yield { \n text: `Error connecting to chat server: ${error.message}`, \n done: true \n };\n }\n}\n\n// Helper function to extract only new text from incoming chunks\nfunction extractNewText(incomingText: string, currentText: string): string {\n if (!currentText) return incomingText;\n if (currentText.endsWith(incomingText)) return '';\n \n if (incomingText.length > currentText.length) {\n if (incomingText.startsWith(currentText)) {\n return incomingText.slice(currentText.length);\n }\n \n let i = 0;\n const minLength = Math.min(currentText.length, incomingText.length);\n while (i < minLength && currentText[i] === incomingText[i]) {\n i++;\n }\n \n if (i > currentText.length / 2) {\n return incomingText.slice(i);\n }\n }\n \n return incomingText;\n}\n\n// New function to send tools request\nexport async function sendToolsRequest(tools: Array<{ name: string; parameters: Record<string, any> }>): Promise<MCPResponse> {\n const API_URL = getApiUrl();\n \n const response = await fetch(`${API_URL}/v1/chat`, getFetchOptions(API_URL, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json'\n },\n body: JSON.stringify(createMCPToolsRequest(tools)),\n }));\n\n if (!response.ok) {\n const errorText = await response.text();\n throw new Error(`Network response was not ok: ${response.status} ${errorText}`);\n }\n\n const data = await response.json() as MCPResponse;\n if (data.error) {\n throw new Error(`MCP Error: ${data.error.message}`);\n }\n\n return data;\n}"],"names":["configuredApiUrl","configuredApiKey","configureApi","apiUrl","apiKey","getApiUrl","getApiKey","getFetchOptions","options","requestId","createMCPRequest","message","stream","createMCPToolsRequest","tools","streamChat","_a","_b","_c","_d","_e","_f","_g","_h","_i","API_URL","response","errorText","data","reader","decoder","buffer","currentFullText","done","value","chunk","lines","line","jsonText","content","newText","extractNewText","error","incomingText","currentText","i","minLength","sendToolsRequest"],"mappings":"AAyDA,IAAIA,IAAkC,MAClCC,IAAkC;AAGzB,MAAAC,IAAe,CAACC,GAAgBC,MAAyB;AACpE,MAAI,CAACD,KAAU,OAAOA,KAAW;AACzB,UAAA,IAAI,MAAM,gCAAgC;AAElD,MAAI,CAACC,KAAU,OAAOA,KAAW;AACzB,UAAA,IAAI,MAAM,gCAAgC;AAE/B,EAAAJ,IAAAG,GACAF,IAAAG;AACrB,GAGMC,IAAY,MAAc;AAC9B,MAAI,CAACL;AACG,UAAA,IAAI,MAAM,yGAAyG;AAEpH,SAAAA;AACT,GAGMM,IAAY,MAAc;AAC9B,MAAI,CAACL;AACG,UAAA,IAAI,MAAM,sGAAsG;AAEjH,SAAAA;AACT,GAGMM,IAAkB,CAACJ,GAAgBK,IAAuB,OAA0B;AACxE,EAAAL,EAAO,WAAW,QAAQ;AAY1C,QAAMM,IAAY,KAAK,IAAI,EAAE,SAAS,EAAE,IAAI,KAAK,OAAS,EAAA,SAAS,EAAE,EAAE,UAAU,CAAC;AAG3E,SAAA;AAAA,IACL,GAAGD;AAAA,IACH,SAAS;AAAA,MACP,GAAGA,EAAQ;AAAA,MACX,YAAc;AAAA,MACd,gBAAgBC;AAAA,MAChB,aAAa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,GAAsBC,GAA6B;AACrE,MAAA,CAACA,EAAoB,QAAAD;AACzB,MAAIC,EAAY,SAASD,CAAY,EAAU,QAAA;AAE3C,MAAAA,EAAa,SAASC,EAAY,QAAQ;AACxC,QAAAD,EAAa,WAAWC,CAAW;AAC9B,aAAAD,EAAa,MAAMC,EAAY,MAAM;AAG9C,QAAIC,IAAI;AACR,UAAMC,IAAY,KAAK,IAAIF,EAAY,QAAQD,EAAa,MAAM;AAClE,WAAOE,IAAIC,KAAaF,EAAYC,CAAC,MAAMF,EAAaE,CAAC;AACvD,MAAAA;AAGE,QAAAA,IAAID,EAAY,SAAS;AACpB,aAAAD,EAAa,MAAME,CAAC;AAAA,EAC7B;AAGK,SAAAF;AACT;AAGA,eAAsBI,EAAiBjC,GAAuF;AAC5H,QAAMW,IAAUpB,EAAU,GAEpBqB,IAAW,MAAM,MAAM,GAAGD,CAAO,YAAYlB,EAAgBkB,GAAS;AAAA,IAC1E,QAAQ;AAAA,IACR,SAAS;AAAA,MACP,gBAAgB;AAAA,IAClB;AAAA,IACA,MAAM,KAAK,UAAUZ,EAAsBC,CAAK,CAAC;AAAA,EAAA,CAClD,CAAC;AAEE,MAAA,CAACY,EAAS,IAAI;AACV,UAAAC,IAAY,MAAMD,EAAS,KAAK;AACtC,UAAM,IAAI,MAAM,gCAAgCA,EAAS,MAAM,IAAIC,CAAS,EAAE;AAAA,EAAA;AAG1E,QAAAC,IAAO,MAAMF,EAAS,KAAK;AACjC,MAAIE,EAAK;AACP,UAAM,IAAI,MAAM,cAAcA,EAAK,MAAM,OAAO,EAAE;AAG7C,SAAAA;AACT;"}
|
|
1
|
+
{"version":3,"file":"api.mjs","sources":["../api.ts"],"sourcesContent":["// For Node.js environments, we can use http.Agent for connection pooling\nlet httpAgent: any = null;\nlet httpsAgent: any = null;\n\n// Define the StreamResponse interface\nexport interface StreamResponse {\n text: string;\n done: boolean;\n}\n\nexport interface ChatResponse {\n response: string;\n}\n\n// MCP Protocol interfaces\ninterface MCPRequest {\n jsonrpc: \"2.0\";\n method: string;\n params: {\n name: string;\n arguments: {\n messages?: Array<{\n role: string;\n content: string;\n }>;\n stream?: boolean;\n tools?: Array<{\n name: string;\n parameters: Record<string, any>;\n }>;\n };\n };\n id: string;\n}\n\ninterface MCPResponse {\n jsonrpc: \"2.0\";\n id: string;\n result?: {\n type?: \"start\" | \"chunk\" | \"complete\";\n chunk?: {\n content: string;\n };\n output?: {\n messages: Array<{\n role: string;\n content: string;\n }>;\n };\n };\n error?: {\n code: number;\n message: string;\n };\n}\n\n// Store the configured API URL, key, and session ID\nlet configuredApiUrl: string | null = null;\nlet configuredApiKey: string | null = null;\nlet configuredSessionId: string | null = null;\n\n// Configure the API with a custom URL, API key, and session ID\nexport const configureApi = (apiUrl: string, apiKey: string, sessionId: string): void => {\n if (!apiUrl || typeof apiUrl !== 'string') {\n throw new Error('API URL must be a valid string');\n }\n if (!apiKey || typeof apiKey !== 'string') {\n throw new Error('API key must be a valid string');\n }\n if (!sessionId || typeof sessionId !== 'string') {\n throw new Error('Session ID must be a valid string');\n }\n configuredApiUrl = apiUrl;\n configuredApiKey = apiKey;\n configuredSessionId = sessionId;\n}\n\n// Get the configured API URL or throw an error if not configured\nconst getApiUrl = (): string => {\n if (!configuredApiUrl) {\n throw new Error('API URL not configured. Please call configureApi() with your server URL before using any API functions.');\n }\n return configuredApiUrl;\n};\n\n// Get the configured API key or throw an error if not configured\nconst getApiKey = (): string => {\n if (!configuredApiKey) {\n throw new Error('API key not configured. Please call configureApi() with your API key before using any API functions.');\n }\n return configuredApiKey;\n};\n\n// Get the configured session ID or throw an error if not configured\nconst getSessionId = (): string => {\n if (!configuredSessionId) {\n throw new Error('Session ID not configured. Please call configureApi() with your session ID before using any API functions.');\n }\n return configuredSessionId;\n};\n\n// Helper to get fetch options with connection pooling if available\nconst getFetchOptions = (apiUrl: string, options: RequestInit = {}): RequestInit | any => {\n const isHttps = apiUrl.startsWith('https:');\n \n // Only use agents in Node.js environment\n if (typeof window === 'undefined') {\n if (isHttps && httpsAgent) {\n return { ...options, agent: httpsAgent } as any;\n } else if (httpAgent) {\n return { ...options, agent: httpAgent } as any;\n }\n }\n \n // Browser environment\n const requestId = Date.now().toString(36) + Math.random().toString(36).substring(2);\n \n // Use keep-alive header in browser environments\n const headers: Record<string, string> = {\n 'Connection': 'keep-alive',\n 'X-Request-ID': requestId,\n 'X-API-Key': getApiKey(),\n 'X-Session-ID': getSessionId()\n };\n \n return {\n ...options,\n headers: {\n ...options.headers,\n ...headers\n }\n };\n};\n\n// Create MCP request\nconst createMCPRequest = (message: string, stream: boolean = true): MCPRequest => {\n return {\n jsonrpc: \"2.0\",\n method: \"tools/call\",\n params: {\n name: \"chat\",\n arguments: {\n messages: [\n { role: \"user\", content: message }\n ],\n stream\n }\n },\n id: Date.now().toString(36) + Math.random().toString(36).substring(2)\n };\n};\n\n// Create MCP tools request\nconst createMCPToolsRequest = (tools: Array<{ name: string; parameters: Record<string, any> }>): MCPRequest => {\n return {\n jsonrpc: \"2.0\",\n method: \"tools/call\",\n params: {\n name: \"tools\",\n arguments: {\n tools\n }\n },\n id: Date.now().toString(36) + Math.random().toString(36).substring(2)\n };\n};\n\nexport async function* streamChat(\n message: string,\n stream: boolean = true\n): AsyncGenerator<StreamResponse> {\n try {\n const API_URL = getApiUrl();\n \n // Add timeout to the fetch request\n const controller = new AbortController();\n const timeoutId = setTimeout(() => controller.abort(), 10000); // 10 second timeout\n\n const response = await fetch(`${API_URL}/v1/chat`, {\n ...getFetchOptions(API_URL, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n 'Accept': stream ? 'text/event-stream' : 'application/json'\n },\n body: JSON.stringify(createMCPRequest(message, stream)),\n }),\n signal: controller.signal\n });\n\n clearTimeout(timeoutId);\n\n if (!response.ok) {\n const errorText = await response.text();\n throw new Error(`Network response was not ok: ${response.status} ${errorText}`);\n }\n\n if (!stream) {\n // Handle non-streaming response\n const data = await response.json() as MCPResponse;\n if (data.error) {\n throw new Error(`MCP Error: ${data.error.message}`);\n }\n if (data.result?.output?.messages?.[0]?.content) {\n yield {\n text: data.result.output.messages[0].content,\n done: true\n };\n }\n return;\n }\n \n const reader = response.body?.getReader();\n if (!reader) throw new Error('No reader available');\n\n const decoder = new TextDecoder();\n let buffer = '';\n let currentFullText = '';\n\n try {\n while (true) {\n const { done, value } = await reader.read();\n if (done) break;\n\n const chunk = decoder.decode(value, { stream: true });\n buffer += chunk;\n const lines = buffer.split('\\n');\n buffer = lines.pop() || '';\n\n for (const line of lines) {\n if (line.trim() && line.startsWith('data: ')) {\n try {\n const jsonText = line.slice(6).trim();\n if (jsonText === '[DONE]') {\n yield { text: '', done: true };\n break;\n }\n\n const data = JSON.parse(jsonText) as MCPResponse;\n \n if (data.result) {\n let content = '';\n \n if (data.result.type === 'start') {\n continue;\n } else if (data.result.type === 'chunk' && data.result.chunk) {\n content = data.result.chunk.content;\n } else if (data.result.type === 'complete' && data.result.output?.messages?.[0]) {\n content = data.result.output.messages[0].content;\n }\n\n if (content) {\n const newText = extractNewText(content, currentFullText);\n if (newText) {\n currentFullText += newText;\n yield {\n text: newText,\n done: data.result.type === 'complete'\n };\n } else if (data.result.type === 'complete') {\n yield { text: '', done: true };\n }\n }\n }\n } catch (error) {\n console.warn('Error parsing JSON chunk:', line, 'Error:', error);\n }\n }\n }\n }\n } finally {\n reader.releaseLock();\n }\n\n // Handle any remaining buffer\n if (buffer && buffer.startsWith('data: ')) {\n try {\n const jsonText = buffer.slice(6).trim();\n if (jsonText !== '[DONE]') {\n const data = JSON.parse(jsonText) as MCPResponse;\n if (data.result?.chunk?.content) {\n const newText = extractNewText(data.result.chunk.content, currentFullText);\n if (newText) {\n yield {\n text: newText,\n done: data.result.type === 'complete'\n };\n }\n }\n }\n } catch (error) {\n console.warn('Error parsing final JSON buffer:', buffer, 'Error:', error);\n }\n }\n } catch (error: any) {\n if (error.name === 'AbortError') {\n yield { \n text: 'Connection timed out. Please check if the server is running.', \n done: true \n };\n } else if (error.name === 'TypeError' && error.message.includes('Failed to fetch')) {\n yield { \n text: 'Could not connect to the server. Please check if the server is running.', \n done: true \n };\n } else {\n yield { \n text: `Error: ${error.message}`, \n done: true \n };\n }\n }\n}\n\n// Helper function to extract only new text from incoming chunks\nfunction extractNewText(incomingText: string, currentText: string): string {\n if (!currentText) return incomingText;\n if (currentText.endsWith(incomingText)) return '';\n \n if (incomingText.length > currentText.length) {\n if (incomingText.startsWith(currentText)) {\n return incomingText.slice(currentText.length);\n }\n \n let i = 0;\n const minLength = Math.min(currentText.length, incomingText.length);\n while (i < minLength && currentText[i] === incomingText[i]) {\n i++;\n }\n \n if (i > currentText.length / 2) {\n return incomingText.slice(i);\n }\n }\n \n return incomingText;\n}\n\n// New function to send tools request\nexport async function sendToolsRequest(tools: Array<{ name: string; parameters: Record<string, any> }>): Promise<MCPResponse> {\n const API_URL = getApiUrl();\n \n const response = await fetch(`${API_URL}/v1/chat`, getFetchOptions(API_URL, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json'\n },\n body: JSON.stringify(createMCPToolsRequest(tools)),\n }));\n\n if (!response.ok) {\n const errorText = await response.text();\n throw new Error(`Network response was not ok: ${response.status} ${errorText}`);\n }\n\n const data = await response.json() as MCPResponse;\n if (data.error) {\n throw new Error(`MCP Error: ${data.error.message}`);\n }\n\n return data;\n}"],"names":["configuredApiUrl","configuredApiKey","configuredSessionId","configureApi","apiUrl","apiKey","sessionId","getApiUrl","getApiKey","getSessionId","getFetchOptions","options","headers","createMCPRequest","message","stream","createMCPToolsRequest","tools","streamChat","_a","_b","_c","_d","_e","_f","_g","_h","_i","API_URL","controller","timeoutId","response","errorText","data","reader","decoder","buffer","currentFullText","done","value","chunk","lines","line","jsonText","content","newText","extractNewText","error","incomingText","currentText","i","minLength","sendToolsRequest"],"mappings":"AAyDA,IAAIA,IAAkC,MAClCC,IAAkC,MAClCC,IAAqC;AAGlC,MAAMC,IAAe,CAACC,GAAgBC,GAAgBC,MAA4B;AACvF,MAAI,CAACF,KAA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AAoB,QAAAD;AACzB,MAAIC,EAAY,SAASD,CAAY,EAAU,QAAA;AAE3C,MAAAA,EAAa,SAASC,EAAY,QAAQ;AACxC,QAAAD,EAAa,WAAWC,CAAW;AAC9B,aAAAD,EAAa,MAAMC,EAAY,MAAM;AAG9C,QAAIC,IAAI;AACR,UAAMC,IAAY,KAAK,IAAIF,EAAY,QAAQD,EAAa,MAAM;AAClE,WAAOE,IAAIC,KAAaF,EAAYC,CAAC,MAAMF,EAAaE,CAAC;AACvD,MAAAA;AAGE,QAAAA,IAAID,EAAY,SAAS;AACpB,aAAAD,EAAa,MAAME,CAAC;AAAA,EAC7B;AAGK,SAAAF;AACT;AAGA,eAAsBI,EAAiBnC,GAAuF;AAC5H,QAAMW,IAAUrB,EAAU,GAEpBwB,IAAW,MAAM,MAAM,GAAGH,CAAO,YAAYlB,EAAgBkB,GAAS;AAAA,IAC1E,QAAQ;AAAA,IACR,SAAS;AAAA,MACP,gBAAgB;AAAA,IAClB;AAAA,IACA,MAAM,KAAK,UAAUZ,EAAsBC,CAAK,CAAC;AAAA,EAAA,CAClD,CAAC;AAEE,MAAA,CAACc,EAAS,IAAI;AACV,UAAAC,IAAY,MAAMD,EAAS,KAAK;AACtC,UAAM,IAAI,MAAM,gCAAgCA,EAAS,MAAM,IAAIC,CAAS,EAAE;AAAA,EAAA;AAG1E,QAAAC,IAAO,MAAMF,EAAS,KAAK;AACjC,MAAIE,EAAK;AACP,UAAM,IAAI,MAAM,cAAcA,EAAK,MAAM,OAAO,EAAE;AAG7C,SAAAA;AACT;"}
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@schmitech/chatbot-api",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "0.4.
|
|
5
|
-
"description": "API client for the
|
|
4
|
+
"version": "0.4.2",
|
|
5
|
+
"description": "API client for the ORBIT MCP server",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "./dist/api.cjs",
|
|
8
8
|
"module": "./dist/api.mjs",
|