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 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
- ## ⚠️ IMPORTANT NOTICE ⚠️
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
- **This package is created solely for the purpose of setting up OIDC (OpenID Connect) trusted publishing with npm.**
5
+ ## Features
6
6
 
7
- This is **NOT** a functional package and contains **NO** code or functionality beyond the OIDC setup configuration.
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
- ## Purpose
14
+ ## Installation
10
15
 
11
- This package exists to:
12
- 1. Configure OIDC trusted publishing for the package name `pupt-react`
13
- 2. Enable secure, token-less publishing from CI/CD workflows
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
- ## What is OIDC Trusted Publishing?
20
+ ## Quick Start
17
21
 
18
- OIDC trusted publishing allows package maintainers to publish packages directly from their CI/CD workflows without needing to manage npm access tokens. Instead, it uses OpenID Connect to establish trust between the CI/CD provider (like GitHub Actions) and npm.
22
+ ### Basic Setup
19
23
 
20
- ## Setup Instructions
24
+ Wrap your application with `PuptProvider` to enable pupt-lib integration:
21
25
 
22
- To properly configure OIDC trusted publishing for this package:
26
+ ```tsx
27
+ import { PuptProvider, PromptRenderer } from "pupt-react";
23
28
 
24
- 1. Go to [npmjs.com](https://www.npmjs.com/) and navigate to your package settings
25
- 2. Configure the trusted publisher (e.g., GitHub Actions)
26
- 3. Specify the repository and workflow that should be allowed to publish
27
- 4. Use the configured workflow to publish your actual package
29
+ function App() {
30
+ return (
31
+ <PuptProvider>
32
+ <MyPromptComponent />
33
+ </PuptProvider>
34
+ );
35
+ }
36
+ ```
28
37
 
29
- ## DO NOT USE THIS PACKAGE
38
+ ### Rendering a Prompt
30
39
 
31
- This package is a placeholder for OIDC configuration only. It:
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
- ## More Information
42
+ ```tsx
43
+ import { PromptRenderer } from "pupt-react";
38
44
 
39
- For more details about npm's trusted publishing feature, see:
40
- - [npm Trusted Publishing Documentation](https://docs.npmjs.com/generating-provenance-statements)
41
- - [GitHub Actions OIDC Documentation](https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/about-security-hardening-with-openid-connect)
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
- **Maintained for OIDC setup purposes only**
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