pupt-react 0.0.1 → 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/LICENSE +21 -0
- package/README.md +258 -28
- package/dist/index.cjs +868 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +652 -0
- package/dist/index.js +868 -0
- package/dist/index.js.map +1 -0
- package/package.json +103 -7
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 pupt-react contributors
|
|
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.
|
package/README.md
CHANGED
|
@@ -1,45 +1,275 @@
|
|
|
1
1
|
# pupt-react
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A headless React component library for integrating [pupt-lib](https://github.com/apowers313/pupt-lib) into web applications. Provides hooks and render-prop components for prompt transformation, rendering, and user input collection.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
## Features
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
- **Headless Components**: Full UI flexibility with render-prop patterns
|
|
8
|
+
- **React Hooks**: Access pupt-lib functionality with idiomatic React APIs
|
|
9
|
+
- **Ask System Integration**: Collect and validate user inputs with type-safe forms
|
|
10
|
+
- **Search Support**: Built-in prompt search functionality
|
|
11
|
+
- **Post-Actions**: Handle post-execution actions from prompts
|
|
12
|
+
- **TypeScript**: Full type definitions included
|
|
8
13
|
|
|
9
|
-
##
|
|
14
|
+
## Installation
|
|
10
15
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
3. Establish provenance for packages published under this name
|
|
16
|
+
```bash
|
|
17
|
+
npm install pupt-react pupt-lib react react-dom
|
|
18
|
+
```
|
|
15
19
|
|
|
16
|
-
##
|
|
20
|
+
## Quick Start
|
|
17
21
|
|
|
18
|
-
|
|
22
|
+
### Basic Setup
|
|
19
23
|
|
|
20
|
-
|
|
24
|
+
Wrap your application with `PuptProvider` to enable pupt-lib integration:
|
|
21
25
|
|
|
22
|
-
|
|
26
|
+
```tsx
|
|
27
|
+
import { PuptProvider, PromptRenderer } from "pupt-react";
|
|
23
28
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
29
|
+
function App() {
|
|
30
|
+
return (
|
|
31
|
+
<PuptProvider>
|
|
32
|
+
<MyPromptComponent />
|
|
33
|
+
</PuptProvider>
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
```
|
|
28
37
|
|
|
29
|
-
|
|
38
|
+
### Rendering a Prompt
|
|
30
39
|
|
|
31
|
-
|
|
32
|
-
- Contains no executable code
|
|
33
|
-
- Provides no functionality
|
|
34
|
-
- Should not be installed as a dependency
|
|
35
|
-
- Exists only for administrative purposes
|
|
40
|
+
Use `PromptRenderer` with the render-prop pattern for full control over rendering:
|
|
36
41
|
|
|
37
|
-
|
|
42
|
+
```tsx
|
|
43
|
+
import { PromptRenderer } from "pupt-react";
|
|
38
44
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
45
|
+
function MyPromptComponent() {
|
|
46
|
+
const source = `<Prompt name="greeting">
|
|
47
|
+
<Task>Say hello to the user.</Task>
|
|
48
|
+
</Prompt>`;
|
|
42
49
|
|
|
43
|
-
|
|
50
|
+
return (
|
|
51
|
+
<PromptRenderer source={source} autoRender>
|
|
52
|
+
{({ output, error, isRendering, copyToClipboard }) => (
|
|
53
|
+
<div>
|
|
54
|
+
{isRendering ? (
|
|
55
|
+
<p>Rendering...</p>
|
|
56
|
+
) : error ? (
|
|
57
|
+
<p>Error: {error.message}</p>
|
|
58
|
+
) : (
|
|
59
|
+
<>
|
|
60
|
+
<pre>{output}</pre>
|
|
61
|
+
<button onClick={copyToClipboard}>Copy</button>
|
|
62
|
+
</>
|
|
63
|
+
)}
|
|
64
|
+
</div>
|
|
65
|
+
)}
|
|
66
|
+
</PromptRenderer>
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
```
|
|
44
70
|
|
|
45
|
-
|
|
71
|
+
### Using Hooks Directly
|
|
72
|
+
|
|
73
|
+
For more control, use the hooks directly:
|
|
74
|
+
|
|
75
|
+
```tsx
|
|
76
|
+
import { usePupt, usePromptRender } from "pupt-react";
|
|
77
|
+
|
|
78
|
+
function MyComponent() {
|
|
79
|
+
const { transformer, registry } = usePupt();
|
|
80
|
+
const { output, render, isRendering, error } = usePromptRender({
|
|
81
|
+
source: { type: "source", value: "<Prompt><Task>Hello</Task></Prompt>" },
|
|
82
|
+
autoRender: true,
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
return <div>{output}</div>;
|
|
86
|
+
}
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## Components
|
|
90
|
+
|
|
91
|
+
### PuptProvider
|
|
92
|
+
|
|
93
|
+
Context provider that initializes pupt-lib and provides configuration to child components.
|
|
94
|
+
|
|
95
|
+
```tsx
|
|
96
|
+
<PuptProvider
|
|
97
|
+
registry={customRegistry} // Optional custom ComponentRegistry
|
|
98
|
+
searchEngine={searchEngine} // Optional SearchEngine instance
|
|
99
|
+
>
|
|
100
|
+
{children}
|
|
101
|
+
</PuptProvider>
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
### PromptRenderer
|
|
105
|
+
|
|
106
|
+
Headless component for transforming and rendering prompts.
|
|
107
|
+
|
|
108
|
+
```tsx
|
|
109
|
+
<PromptRenderer
|
|
110
|
+
source={source} // Prompt source string
|
|
111
|
+
inputs={inputsMap} // Map of user input values
|
|
112
|
+
autoRender={true} // Auto-render when source changes
|
|
113
|
+
>
|
|
114
|
+
{(props) => (
|
|
115
|
+
// props: output, error, isRendering, pendingInputs, copyToClipboard, isCopied
|
|
116
|
+
)}
|
|
117
|
+
</PromptRenderer>
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### PromptEditor
|
|
121
|
+
|
|
122
|
+
Headless component for editing prompt source with transformation preview.
|
|
123
|
+
|
|
124
|
+
```tsx
|
|
125
|
+
<PromptEditor
|
|
126
|
+
defaultValue={source}
|
|
127
|
+
onChange={handleChange}
|
|
128
|
+
debounce={300}
|
|
129
|
+
>
|
|
130
|
+
{({ inputProps, value, error, isTransforming }) => (
|
|
131
|
+
<textarea {...inputProps} />
|
|
132
|
+
)}
|
|
133
|
+
</PromptEditor>
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
### AskHandler
|
|
137
|
+
|
|
138
|
+
Headless component for handling Ask input requirements.
|
|
139
|
+
|
|
140
|
+
```tsx
|
|
141
|
+
<AskHandler
|
|
142
|
+
element={element}
|
|
143
|
+
onComplete={(inputs) => console.log(inputs)}
|
|
144
|
+
>
|
|
145
|
+
{({ requirements, current, progress, getInputProps, next, previous }) => (
|
|
146
|
+
// Render your custom form UI
|
|
147
|
+
)}
|
|
148
|
+
</AskHandler>
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
## Hooks
|
|
152
|
+
|
|
153
|
+
### usePupt
|
|
154
|
+
|
|
155
|
+
Access the PuptProvider context:
|
|
156
|
+
|
|
157
|
+
```tsx
|
|
158
|
+
const { transformer, registry, searchEngine, isLoading, error } = usePupt();
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
### usePromptRender
|
|
162
|
+
|
|
163
|
+
Transform and render prompts:
|
|
164
|
+
|
|
165
|
+
```tsx
|
|
166
|
+
const {
|
|
167
|
+
source,
|
|
168
|
+
setSource,
|
|
169
|
+
element,
|
|
170
|
+
output,
|
|
171
|
+
error,
|
|
172
|
+
isTransforming,
|
|
173
|
+
isRendering,
|
|
174
|
+
inputRequirements,
|
|
175
|
+
render,
|
|
176
|
+
transform,
|
|
177
|
+
} = usePromptRender({
|
|
178
|
+
source: { type: "source", value: promptString },
|
|
179
|
+
inputs: inputsMap,
|
|
180
|
+
autoRender: true,
|
|
181
|
+
});
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
### useAskIterator
|
|
185
|
+
|
|
186
|
+
Iterate through Ask inputs and collect validated responses:
|
|
187
|
+
|
|
188
|
+
```tsx
|
|
189
|
+
const {
|
|
190
|
+
current,
|
|
191
|
+
currentIndex,
|
|
192
|
+
totalInputs,
|
|
193
|
+
inputs,
|
|
194
|
+
isDone,
|
|
195
|
+
submit,
|
|
196
|
+
next,
|
|
197
|
+
previous,
|
|
198
|
+
reset,
|
|
199
|
+
getValue,
|
|
200
|
+
setValue,
|
|
201
|
+
} = useAskIterator({
|
|
202
|
+
element,
|
|
203
|
+
onComplete: (inputs) => console.log("All inputs collected", inputs),
|
|
204
|
+
});
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
### usePromptSearch
|
|
208
|
+
|
|
209
|
+
Search through available prompts:
|
|
210
|
+
|
|
211
|
+
```tsx
|
|
212
|
+
const { query, setQuery, results, isSearching, clear } = usePromptSearch({
|
|
213
|
+
debounce: 300,
|
|
214
|
+
limit: 10,
|
|
215
|
+
});
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
### usePostActions
|
|
219
|
+
|
|
220
|
+
Handle post-execution actions:
|
|
221
|
+
|
|
222
|
+
```tsx
|
|
223
|
+
const { pendingActions, executedActions, execute, executeAll, dismiss } =
|
|
224
|
+
usePostActions({
|
|
225
|
+
actions,
|
|
226
|
+
handlers: {
|
|
227
|
+
openUrl: (url) => window.open(url),
|
|
228
|
+
},
|
|
229
|
+
});
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
## Demo
|
|
233
|
+
|
|
234
|
+
A demo website showcasing pupt-react capabilities is included. To run locally:
|
|
235
|
+
|
|
236
|
+
```bash
|
|
237
|
+
npm run dev:demo
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
Or build for production:
|
|
241
|
+
|
|
242
|
+
```bash
|
|
243
|
+
npm run build:demo
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
## Development
|
|
247
|
+
|
|
248
|
+
```bash
|
|
249
|
+
# Install dependencies
|
|
250
|
+
npm install
|
|
251
|
+
|
|
252
|
+
# Run tests
|
|
253
|
+
npm test
|
|
254
|
+
|
|
255
|
+
# Run tests with coverage
|
|
256
|
+
npm run test:coverage
|
|
257
|
+
|
|
258
|
+
# Lint code
|
|
259
|
+
npm run lint
|
|
260
|
+
|
|
261
|
+
# Build library
|
|
262
|
+
npm run build
|
|
263
|
+
|
|
264
|
+
# Build demo
|
|
265
|
+
npm run build:demo
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
## Requirements
|
|
269
|
+
|
|
270
|
+
- React 18.0.0 or later
|
|
271
|
+
- pupt-lib (peer dependency)
|
|
272
|
+
|
|
273
|
+
## License
|
|
274
|
+
|
|
275
|
+
MIT
|