@voltx/ui 0.2.0 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +108 -0
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +9 -19
- package/LICENSE +0 -21
package/README.md
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<strong>@voltx/ui</strong><br/>
|
|
3
|
+
<em>React hooks for AI-powered interfaces — useChat, useAgent</em>
|
|
4
|
+
</p>
|
|
5
|
+
|
|
6
|
+
<p align="center">
|
|
7
|
+
<a href="https://www.npmjs.com/package/@voltx/ui"><img src="https://img.shields.io/npm/v/@voltx/ui?color=blue" alt="npm" /></a>
|
|
8
|
+
<a href="https://www.npmjs.com/package/@voltx/ui"><img src="https://img.shields.io/npm/dm/@voltx/ui" alt="downloads" /></a>
|
|
9
|
+
<a href="https://github.com/codewithshail/voltx/blob/main/LICENSE"><img src="https://img.shields.io/npm/l/@voltx/ui" alt="license" /></a>
|
|
10
|
+
</p>
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
React hooks for building AI chat interfaces. Part of the [VoltX](https://github.com/codewithshail/voltx) framework.
|
|
15
|
+
|
|
16
|
+
## Installation
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
npm install @voltx/ui
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
> Requires `react` as a peer dependency.
|
|
23
|
+
|
|
24
|
+
## useChat
|
|
25
|
+
|
|
26
|
+
Full-featured chat hook with message management, loading states, and error handling.
|
|
27
|
+
|
|
28
|
+
```tsx
|
|
29
|
+
import { useChat } from "@voltx/ui";
|
|
30
|
+
|
|
31
|
+
function ChatPage() {
|
|
32
|
+
const { messages, input, setInput, sendMessage, isLoading, error, reset } = useChat({
|
|
33
|
+
api: "/api/chat",
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
return (
|
|
37
|
+
<div>
|
|
38
|
+
{messages.map((msg) => (
|
|
39
|
+
<div key={msg.id}>
|
|
40
|
+
<strong>{msg.role}:</strong> {msg.content}
|
|
41
|
+
</div>
|
|
42
|
+
))}
|
|
43
|
+
|
|
44
|
+
<form onSubmit={(e) => { e.preventDefault(); sendMessage(); }}>
|
|
45
|
+
<input value={input} onChange={(e) => setInput(e.target.value)} />
|
|
46
|
+
<button type="submit" disabled={isLoading}>Send</button>
|
|
47
|
+
</form>
|
|
48
|
+
</div>
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### Options
|
|
54
|
+
|
|
55
|
+
```ts
|
|
56
|
+
useChat({
|
|
57
|
+
api: "/api/chat", // API endpoint (default: "/api/chat")
|
|
58
|
+
initialMessages: [], // Pre-populate messages
|
|
59
|
+
onResponse: (res) => {}, // Called when response is received
|
|
60
|
+
onError: (err) => {}, // Called on error
|
|
61
|
+
});
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### Return Value
|
|
65
|
+
|
|
66
|
+
| Property | Type | Description |
|
|
67
|
+
|----------|------|-------------|
|
|
68
|
+
| `messages` | `ChatMessage[]` | All messages in the conversation |
|
|
69
|
+
| `input` | `string` | Current input value |
|
|
70
|
+
| `setInput` | `function` | Update input value |
|
|
71
|
+
| `sendMessage` | `function` | Send a message |
|
|
72
|
+
| `isLoading` | `boolean` | Whether a request is in progress |
|
|
73
|
+
| `error` | `Error \| null` | Last error |
|
|
74
|
+
| `reset` | `function` | Clear all messages |
|
|
75
|
+
|
|
76
|
+
## useAgent
|
|
77
|
+
|
|
78
|
+
Hook for interacting with VoltX agents.
|
|
79
|
+
|
|
80
|
+
```tsx
|
|
81
|
+
import { useAgent } from "@voltx/ui";
|
|
82
|
+
|
|
83
|
+
function AgentPage() {
|
|
84
|
+
const { run, isRunning, error } = useAgent({
|
|
85
|
+
api: "/api/agent",
|
|
86
|
+
agentName: "assistant",
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
const handleRun = async () => {
|
|
90
|
+
const result = await run("What's the weather in Tokyo?");
|
|
91
|
+
console.log(result);
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
return (
|
|
95
|
+
<button onClick={handleRun} disabled={isRunning}>
|
|
96
|
+
{isRunning ? "Thinking..." : "Ask Agent"}
|
|
97
|
+
</button>
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## Part of VoltX
|
|
103
|
+
|
|
104
|
+
This package is part of the [VoltX](https://github.com/codewithshail/voltx) framework. See the [monorepo](https://github.com/codewithshail/voltx) for full documentation.
|
|
105
|
+
|
|
106
|
+
## License
|
|
107
|
+
|
|
108
|
+
[MIT](https://github.com/codewithshail/voltx/blob/main/LICENSE) — Made by the [Promptly AI Team](https://buymeacoffee.com/promptlyai)
|
package/dist/index.d.mts
CHANGED
|
@@ -35,6 +35,6 @@ interface UseAgentReturn {
|
|
|
35
35
|
error: Error | null;
|
|
36
36
|
}
|
|
37
37
|
declare function useAgent(options: UseAgentOptions): UseAgentReturn;
|
|
38
|
-
declare const VERSION = "0.1
|
|
38
|
+
declare const VERSION = "0.4.1";
|
|
39
39
|
|
|
40
40
|
export { type ChatMessage, type UseAgentOptions, type UseAgentReturn, type UseChatOptions, type UseChatReturn, VERSION, useAgent, useChat };
|
package/dist/index.d.ts
CHANGED
|
@@ -35,6 +35,6 @@ interface UseAgentReturn {
|
|
|
35
35
|
error: Error | null;
|
|
36
36
|
}
|
|
37
37
|
declare function useAgent(options: UseAgentOptions): UseAgentReturn;
|
|
38
|
-
declare const VERSION = "0.1
|
|
38
|
+
declare const VERSION = "0.4.1";
|
|
39
39
|
|
|
40
40
|
export { type ChatMessage, type UseAgentOptions, type UseAgentReturn, type UseChatOptions, type UseChatReturn, VERSION, useAgent, useChat };
|
package/dist/index.js
CHANGED
package/dist/index.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@voltx/ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"description": "VoltX React hooks — useRAG, useAgent, useChat, useCompletion",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -13,6 +13,11 @@
|
|
|
13
13
|
"require": "./dist/index.js"
|
|
14
14
|
}
|
|
15
15
|
},
|
|
16
|
+
"scripts": {
|
|
17
|
+
"build": "tsup src/index.ts --format cjs,esm --dts --external react",
|
|
18
|
+
"dev": "tsup src/index.ts --format cjs,esm --dts --external react --watch",
|
|
19
|
+
"clean": "rm -rf dist"
|
|
20
|
+
},
|
|
16
21
|
"peerDependencies": {
|
|
17
22
|
"react": ">=18.0.0"
|
|
18
23
|
},
|
|
@@ -22,9 +27,7 @@
|
|
|
22
27
|
"tsup": "^8.0.0",
|
|
23
28
|
"typescript": "^5.7.0"
|
|
24
29
|
},
|
|
25
|
-
"files": [
|
|
26
|
-
"dist"
|
|
27
|
-
],
|
|
30
|
+
"files": ["dist"],
|
|
28
31
|
"license": "MIT",
|
|
29
32
|
"repository": {
|
|
30
33
|
"type": "git",
|
|
@@ -33,18 +36,5 @@
|
|
|
33
36
|
},
|
|
34
37
|
"homepage": "https://voltx.co.in",
|
|
35
38
|
"bugs": "https://github.com/codewithshail/voltx/issues",
|
|
36
|
-
"keywords": [
|
|
37
|
-
|
|
38
|
-
"react",
|
|
39
|
-
"hooks",
|
|
40
|
-
"useChat",
|
|
41
|
-
"useAgent",
|
|
42
|
-
"ai",
|
|
43
|
-
"ui"
|
|
44
|
-
],
|
|
45
|
-
"scripts": {
|
|
46
|
-
"build": "tsup src/index.ts --format cjs,esm --dts --external react",
|
|
47
|
-
"dev": "tsup src/index.ts --format cjs,esm --dts --external react --watch",
|
|
48
|
-
"clean": "rm -rf dist"
|
|
49
|
-
}
|
|
50
|
-
}
|
|
39
|
+
"keywords": ["voltx", "react", "hooks", "useChat", "useAgent", "ai", "ui"]
|
|
40
|
+
}
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2025 Promptly AI Team
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|