use-vibes 0.1.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.md +232 -0
- package/README.md +304 -0
- package/dist/bookmarklet.html +89 -0
- package/dist/bookmarklet.js +1 -0
- package/dist/src/core/vibe.d.ts +19 -0
- package/dist/src/core/vibe.js +23 -0
- package/dist/src/index.d.ts +14 -0
- package/dist/src/index.js +93 -0
- package/dist/src/utils/enhancer.d.ts +20 -0
- package/dist/src/utils/enhancer.js +31 -0
- package/dist/tests/browser/call-ai-mock.d.ts +2 -0
- package/dist/tests/browser/call-ai-mock.js +71 -0
- package/dist/tests/browser/global-setup.d.ts +3 -0
- package/dist/tests/browser/global-setup.js +86 -0
- package/dist/tests/browser/hello-world.test.d.ts +1 -0
- package/dist/tests/browser/hello-world.test.js +350 -0
- package/dist/tests/browser/helpers.d.ts +15 -0
- package/dist/tests/browser/helpers.js +32 -0
- package/dist/tests/browser/setup-browser-mocks.d.ts +1 -0
- package/dist/tests/browser/setup-browser-mocks.js +242 -0
- package/dist/tests/vibe.test.d.ts +1 -0
- package/dist/tests/vibe.test.js +60 -0
- package/package.json +78 -0
- package/src/index.ts +116 -0
package/LICENSE.md
ADDED
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
The contents of this repository are Copyright (c) corresponding authors and
|
|
2
|
+
contributors, licensed under the `Permissive License Stack` meaning either of:
|
|
3
|
+
|
|
4
|
+
- Apache-2.0 Software License: https://www.apache.org/licenses/LICENSE-2.0
|
|
5
|
+
([...4tr2kfsq](https://dweb.link/ipfs/bafkreiankqxazcae4onkp436wag2lj3ccso4nawxqkkfckd6cg4tr2kfsq))
|
|
6
|
+
|
|
7
|
+
- MIT Software License: https://opensource.org/licenses/MIT
|
|
8
|
+
([...vljevcba](https://dweb.link/ipfs/bafkreiepofszg4gfe2gzuhojmksgemsub2h4uy2gewdnr35kswvljevcba))
|
|
9
|
+
|
|
10
|
+
You may not use the contents of this repository except in compliance
|
|
11
|
+
with one of the listed Licenses. For an extended clarification of the
|
|
12
|
+
intent behind the choice of Licensing please refer to
|
|
13
|
+
https://protocol.ai/blog/announcing-the-permissive-license-stack/
|
|
14
|
+
|
|
15
|
+
Unless required by applicable law or agreed to in writing, software
|
|
16
|
+
distributed under the terms listed in this notice is distributed on
|
|
17
|
+
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
|
18
|
+
either express or implied. See each License for the specific language
|
|
19
|
+
governing permissions and limitations under that License.
|
|
20
|
+
|
|
21
|
+
<!--- SPDX-License-Identifier: Apache-2.0 OR MIT -->
|
|
22
|
+
|
|
23
|
+
`SPDX-License-Identifier: Apache-2.0 OR MIT`
|
|
24
|
+
|
|
25
|
+
Verbatim copies of both licenses are included below:
|
|
26
|
+
|
|
27
|
+
<details><summary>Apache-2.0 Software License</summary>
|
|
28
|
+
|
|
29
|
+
```
|
|
30
|
+
Apache License
|
|
31
|
+
Version 2.0, January 2004
|
|
32
|
+
http://www.apache.org/licenses/
|
|
33
|
+
|
|
34
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
35
|
+
|
|
36
|
+
1. Definitions.
|
|
37
|
+
|
|
38
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
39
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
40
|
+
|
|
41
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
42
|
+
the copyright owner that is granting the License.
|
|
43
|
+
|
|
44
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
45
|
+
other entities that control, are controlled by, or are under common
|
|
46
|
+
control with that entity. For the purposes of this definition,
|
|
47
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
48
|
+
direction or management of such entity, whether by contract or
|
|
49
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
50
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
51
|
+
|
|
52
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
53
|
+
exercising permissions granted by this License.
|
|
54
|
+
|
|
55
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
56
|
+
including but not limited to software source code, documentation
|
|
57
|
+
source, and configuration files.
|
|
58
|
+
|
|
59
|
+
"Object" form shall mean any form resulting from mechanical
|
|
60
|
+
transformation or translation of a Source form, including but
|
|
61
|
+
not limited to compiled object code, generated documentation,
|
|
62
|
+
and conversions to other media types.
|
|
63
|
+
|
|
64
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
65
|
+
Object form, made available under the License, as indicated by a
|
|
66
|
+
copyright notice that is included in or attached to the work
|
|
67
|
+
(an example is provided in the Appendix below).
|
|
68
|
+
|
|
69
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
70
|
+
form, that is based on (or derived from) the Work and for which the
|
|
71
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
72
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
73
|
+
of this License, Derivative Works shall not include works that remain
|
|
74
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
75
|
+
the Work and Derivative Works thereof.
|
|
76
|
+
|
|
77
|
+
"Contribution" shall mean any work of authorship, including
|
|
78
|
+
the original version of the Work and any modifications or additions
|
|
79
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
80
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
81
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
82
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
83
|
+
means any form of electronic, verbal, or written communication sent
|
|
84
|
+
to the Licensor or its representatives, including but not limited to
|
|
85
|
+
communication on electronic mailing lists, source code control systems,
|
|
86
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
87
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
88
|
+
excluding communication that is conspicuously marked or otherwise
|
|
89
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
90
|
+
|
|
91
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
92
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
93
|
+
subsequently incorporated within the Work.
|
|
94
|
+
|
|
95
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
96
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
97
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
98
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
99
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
100
|
+
Work and such Derivative Works in Source or Object form.
|
|
101
|
+
|
|
102
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
103
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
104
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
105
|
+
(except as stated in this section) patent license to make, have made,
|
|
106
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
107
|
+
where such license applies only to those patent claims licensable
|
|
108
|
+
by such Contributor that are necessarily infringed by their
|
|
109
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
110
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
111
|
+
institute patent litigation against any entity (including a
|
|
112
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
113
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
114
|
+
or contributory patent infringement, then any patent licenses
|
|
115
|
+
granted to You under this License for that Work shall terminate
|
|
116
|
+
as of the date such litigation is filed.
|
|
117
|
+
|
|
118
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
119
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
120
|
+
modifications, and in Source or Object form, provided that You
|
|
121
|
+
meet the following conditions:
|
|
122
|
+
|
|
123
|
+
(a) You must give any other recipients of the Work or
|
|
124
|
+
Derivative Works a copy of this License; and
|
|
125
|
+
|
|
126
|
+
(b) You must cause any modified files to carry prominent notices
|
|
127
|
+
stating that You changed the files; and
|
|
128
|
+
|
|
129
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
130
|
+
that You distribute, all copyright, patent, trademark, and
|
|
131
|
+
attribution notices from the Source form of the Work,
|
|
132
|
+
excluding those notices that do not pertain to any part of
|
|
133
|
+
the Derivative Works; and
|
|
134
|
+
|
|
135
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
136
|
+
distribution, then any Derivative Works that You distribute must
|
|
137
|
+
include a readable copy of the attribution notices contained
|
|
138
|
+
within such NOTICE file, excluding those notices that do not
|
|
139
|
+
pertain to any part of the Derivative Works, in at least one
|
|
140
|
+
of the following places: within a NOTICE text file distributed
|
|
141
|
+
as part of the Derivative Works; within the Source form or
|
|
142
|
+
documentation, if provided along with the Derivative Works; or,
|
|
143
|
+
within a display generated by the Derivative Works, if and
|
|
144
|
+
wherever such third-party notices normally appear. The contents
|
|
145
|
+
of the NOTICE file are for informational purposes only and
|
|
146
|
+
do not modify the License. You may add Your own attribution
|
|
147
|
+
notices within Derivative Works that You distribute, alongside
|
|
148
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
149
|
+
that such additional attribution notices cannot be construed
|
|
150
|
+
as modifying the License.
|
|
151
|
+
|
|
152
|
+
You may add Your own copyright statement to Your modifications and
|
|
153
|
+
may provide additional or different license terms and conditions
|
|
154
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
155
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
156
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
157
|
+
the conditions stated in this License.
|
|
158
|
+
|
|
159
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
160
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
161
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
162
|
+
this License, without any additional terms or conditions.
|
|
163
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
164
|
+
the terms of any separate license agreement you may have executed
|
|
165
|
+
with Licensor regarding such Contributions.
|
|
166
|
+
|
|
167
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
168
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
169
|
+
except as required for reasonable and customary use in describing the
|
|
170
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
171
|
+
|
|
172
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
173
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
174
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
175
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
176
|
+
implied, including, without limitation, any warranties or conditions
|
|
177
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
178
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
179
|
+
appropriateness of using or redistributing the Work and assume any
|
|
180
|
+
risks associated with Your exercise of permissions under this License.
|
|
181
|
+
|
|
182
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
183
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
184
|
+
unless required by applicable law (such as deliberate and grossly
|
|
185
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
186
|
+
liable to You for damages, including any direct, indirect, special,
|
|
187
|
+
incidental, or consequential damages of any character arising as a
|
|
188
|
+
result of this License or out of the use or inability to use the
|
|
189
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
190
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
191
|
+
other commercial damages or losses), even if such Contributor
|
|
192
|
+
has been advised of the possibility of such damages.
|
|
193
|
+
|
|
194
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
195
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
196
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
197
|
+
or other liability obligations and/or rights consistent with this
|
|
198
|
+
License. However, in accepting such obligations, You may act only
|
|
199
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
200
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
201
|
+
defend, and hold each Contributor harmless for any liability
|
|
202
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
203
|
+
of your accepting any such warranty or additional liability.
|
|
204
|
+
|
|
205
|
+
END OF TERMS AND CONDITIONS
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
</details>
|
|
209
|
+
|
|
210
|
+
<details><summary>MIT Software License</summary>
|
|
211
|
+
|
|
212
|
+
```
|
|
213
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
214
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
215
|
+
in the Software without restriction, including without limitation the rights
|
|
216
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
217
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
218
|
+
furnished to do so, subject to the following conditions:
|
|
219
|
+
|
|
220
|
+
The above copyright notice and this permission notice shall be included in
|
|
221
|
+
all copies or substantial portions of the Software.
|
|
222
|
+
|
|
223
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
224
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
225
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
226
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
227
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
228
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
229
|
+
THE SOFTWARE.
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
</details>
|
package/README.md
ADDED
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
# useVibes - App Gen Anywhere
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/use-vibes)
|
|
4
|
+
[](https://opensource.org/licenses/MIT)
|
|
5
|
+
|
|
6
|
+
useVibes is a vanilla browser TypeScript module that transforms any DOM element into an AI-augmented micro-app using an HTML inject-first approach. It leverages the current page's HTML context to create a rich environment for dynamic content generation, powered by the call-ai library.
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
## Overview
|
|
11
|
+
|
|
12
|
+
- **Purpose**: Transform any DOM element into a self-contained, AI-driven micro-app by extracting and utilizing the page's inherent state.
|
|
13
|
+
- **Core Features**:
|
|
14
|
+
- **Inject-First Approach**: Operates directly on the existing page by capturing document.body.innerHTML, the associated CSS, and a visual snapshot via html2canvas.
|
|
15
|
+
- **Context-Aware Transformation**: Uses the page's current state as a germ to generate dynamic content.
|
|
16
|
+
- **Promise-Based API**: Returns an app instance once the micro-app is injected.
|
|
17
|
+
- **Ongoing Chat Interface**: The app instance provides a chat interface to facilitate live, interactive sessions.
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
## Installation
|
|
22
|
+
|
|
23
|
+
### npm
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
npm install use-vibes
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
### yarn
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
yarn add use-vibes
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### pnpm
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
pnpm add use-vibes
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Basic Usage
|
|
42
|
+
|
|
43
|
+
```javascript
|
|
44
|
+
import { useVibes } from 'use-vibes';
|
|
45
|
+
|
|
46
|
+
// Set the API key for call-ai (required)
|
|
47
|
+
window.CALLAI_API_KEY = 'your-api-key-here';
|
|
48
|
+
|
|
49
|
+
// Get target element (can be a CSS selector string or DOM element)
|
|
50
|
+
const target = document.getElementById('my-app-container');
|
|
51
|
+
|
|
52
|
+
// Apply useVibes to the target with a prompt
|
|
53
|
+
useVibes(target, {
|
|
54
|
+
prompt: 'Create a beautiful hello world message with blue styling'
|
|
55
|
+
}).then(app => {
|
|
56
|
+
console.log('App created:', app);
|
|
57
|
+
}).catch(error => {
|
|
58
|
+
console.error('Error creating app:', error);
|
|
59
|
+
});
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### Return Value
|
|
63
|
+
|
|
64
|
+
The function returns a Promise that resolves to an app instance with the following properties:
|
|
65
|
+
|
|
66
|
+
- **container**: The DOM element into which the micro-app has been injected
|
|
67
|
+
- **database**: An optional property for state management (may be undefined)
|
|
68
|
+
|
|
69
|
+
## Browser Usage
|
|
70
|
+
|
|
71
|
+
### IIFE Bundle
|
|
72
|
+
|
|
73
|
+
If you want to use useVibes directly in the browser without a build step, you can use the IIFE bundle:
|
|
74
|
+
|
|
75
|
+
```html
|
|
76
|
+
<script src="https://unpkg.com/use-vibes@latest/lib/use-vibes.iife.js"></script>
|
|
77
|
+
<script>
|
|
78
|
+
// Set API key
|
|
79
|
+
window.CALLAI_API_KEY = 'your-api-key-here';
|
|
80
|
+
|
|
81
|
+
// Now the global useVibes function is available
|
|
82
|
+
useVibes(document.getElementById('my-element'), {
|
|
83
|
+
prompt: 'Create a beautiful hello world message'
|
|
84
|
+
});
|
|
85
|
+
</script>
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### Bookmarklet
|
|
89
|
+
|
|
90
|
+
The useVibes package also includes a bookmarklet that allows you to test useVibes on any website:
|
|
91
|
+
|
|
92
|
+
1. After installing the package, you'll find a `bookmarklet.html` file in the `dist` directory
|
|
93
|
+
2. Open this file in your browser
|
|
94
|
+
3. Drag the bookmarklet link to your bookmarks bar
|
|
95
|
+
4. Navigate to any website, click the bookmarklet, then click on any element you want to enhance
|
|
96
|
+
5. Enter your prompt when prompted
|
|
97
|
+
|
|
98
|
+
You'll need to edit the bookmarklet to include your API key. See the HTML file for detailed instructions.
|
|
99
|
+
|
|
100
|
+
### Example
|
|
101
|
+
|
|
102
|
+
```javascript
|
|
103
|
+
import { useVibes } from 'useVibes';
|
|
104
|
+
|
|
105
|
+
useVibes("#app", { prompt: "create a todo list with emojis" })
|
|
106
|
+
.then((app) => {
|
|
107
|
+
console.log("Micro-app created successfully!");
|
|
108
|
+
|
|
109
|
+
// Log the container element
|
|
110
|
+
console.log("Injected into:", app.container);
|
|
111
|
+
|
|
112
|
+
// If a database is later configured, it can be accessed via app.database
|
|
113
|
+
if (app.database) {
|
|
114
|
+
console.log("Database configured as:", app.database);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// Use the chat interface to send a message to the AI
|
|
118
|
+
app.chat.sendMessage("Hello, vibe!")
|
|
119
|
+
.then(() => console.log("Message sent successfully"))
|
|
120
|
+
.catch((err) => console.error("Error sending message:", err));
|
|
121
|
+
})
|
|
122
|
+
.catch((error) => {
|
|
123
|
+
console.error("Error during injection:", error);
|
|
124
|
+
});
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
---
|
|
128
|
+
|
|
129
|
+
## Quick Start
|
|
130
|
+
|
|
131
|
+
1. **Include the Module**: Import or bundle useVibes as an ESM module in your project.
|
|
132
|
+
2. **Prepare Your HTML**: Ensure your page includes a target element (e.g., `<div id="app"></div>`) for the micro-app.
|
|
133
|
+
3. **Initialize useVibes**: Call useVibes with your target and configuration. The module will capture the page's state, transform it based on your prompt, and inject the resulting micro-app into your target element.
|
|
134
|
+
|
|
135
|
+
---
|
|
136
|
+
|
|
137
|
+
## Architecture Overview
|
|
138
|
+
|
|
139
|
+
- **Purpose**: Build a lightweight, agentic editor that transforms any div into a dynamic micro-app. The module leverages a minimal core—using Fireproof for local persistence and callAi for AI interactions—while preserving the page's inherent structure and style.
|
|
140
|
+
- **Architecture**:
|
|
141
|
+
- **HTML Injection-First**: The library is injected into a page and operates on the current DOM state.
|
|
142
|
+
- **Vanilla Browser Module**: Written in TypeScript and built as an ESM module suitable for distribution via esm.sh/jsr style.
|
|
143
|
+
|
|
144
|
+
---
|
|
145
|
+
|
|
146
|
+
## Testing
|
|
147
|
+
|
|
148
|
+
The useVibes library includes a comprehensive testing suite to ensure functionality across different browsers and use cases.
|
|
149
|
+
|
|
150
|
+
### Browser Testing
|
|
151
|
+
|
|
152
|
+
Browser tests are implemented using Playwright and run on Chrome, Firefox, and WebKit (Safari). The test infrastructure uses a custom build process to create a test bundle with mocked dependencies, allowing tests to run without making actual API calls.
|
|
153
|
+
|
|
154
|
+
```bash
|
|
155
|
+
# Run browser tests
|
|
156
|
+
pnpm test:browser
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
This command will:
|
|
160
|
+
1. Build a test-specific bundle using the `build-browser-test.js` script
|
|
161
|
+
2. Set up browser mocks for all three browser engines
|
|
162
|
+
3. Run the Playwright tests with proper reporting
|
|
163
|
+
|
|
164
|
+
### Unit Testing
|
|
165
|
+
|
|
166
|
+
```bash
|
|
167
|
+
# Run unit tests
|
|
168
|
+
pnpm test:unit
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
### Linting and TypeScript Validation
|
|
172
|
+
|
|
173
|
+
```bash
|
|
174
|
+
# Check types
|
|
175
|
+
pnpm typecheck
|
|
176
|
+
|
|
177
|
+
# Run linter
|
|
178
|
+
pnpm lint
|
|
179
|
+
|
|
180
|
+
# Run linter with auto-fixes
|
|
181
|
+
pnpm lint --fix
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
## Directory Structure
|
|
185
|
+
|
|
186
|
+
- **src/**: Contains the source code for the useVibes library.
|
|
187
|
+
- **fixtures/**: A collection of HTML challenge files. These fixtures serve as test cases for validating that useVibes can handle a variety of page structures.
|
|
188
|
+
- **tests/**: Test suites including browser and unit tests.
|
|
189
|
+
- **browser/**: Playwright browser tests with mock implementations.
|
|
190
|
+
- **unit/**: Unit tests for core functionality.
|
|
191
|
+
- **scripts/**: Build scripts and utilities.
|
|
192
|
+
- **docs/**: Documentation directory which includes:
|
|
193
|
+
- **llms.txt**: A text file specifying the details and technical context for LLM integrations and other project guidelines.
|
|
194
|
+
|
|
195
|
+
---
|
|
196
|
+
|
|
197
|
+
## Prerequisites
|
|
198
|
+
|
|
199
|
+
- Node.js (v14 or higher)
|
|
200
|
+
- pnpm package manager
|
|
201
|
+
- A modern web browser for testing
|
|
202
|
+
|
|
203
|
+
---
|
|
204
|
+
|
|
205
|
+
## Getting Started
|
|
206
|
+
|
|
207
|
+
1. **Clone the Repository**:
|
|
208
|
+
```
|
|
209
|
+
git clone https://github.com/fireproof-storage/use-vibes.git
|
|
210
|
+
cd use-vibes
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
2. **Install Dependencies**:
|
|
214
|
+
```
|
|
215
|
+
pnpm install
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
3. **Build the Project**:
|
|
219
|
+
The project is configured to compile the TypeScript source into an ESM module suitable for browser use.
|
|
220
|
+
```
|
|
221
|
+
pnpm run build
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
---
|
|
225
|
+
|
|
226
|
+
## Testing
|
|
227
|
+
|
|
228
|
+
### Fixture Loading Test
|
|
229
|
+
|
|
230
|
+
Ensure that HTML fixtures load correctly:
|
|
231
|
+
1. Open a test HTML file from the fixtures/ directory in your browser.
|
|
232
|
+
2. Verify that the page loads as expected without any library interference.
|
|
233
|
+
|
|
234
|
+
### Library Injection Test
|
|
235
|
+
|
|
236
|
+
Verify that useVibes loads and executes a basic operation:
|
|
237
|
+
1. Create a simple test page that includes the built useVibes module.
|
|
238
|
+
2. Use the library to inject a "hello world" string into a target element. For example:
|
|
239
|
+
|
|
240
|
+
```html
|
|
241
|
+
<!DOCTYPE html>
|
|
242
|
+
<html lang="en">
|
|
243
|
+
<head>
|
|
244
|
+
<meta charset="UTF-8">
|
|
245
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
246
|
+
<title>useVibes Test</title>
|
|
247
|
+
<!-- Direct ESM import from source during development -->
|
|
248
|
+
<script type="module">
|
|
249
|
+
// Import directly from source files
|
|
250
|
+
import useVibe from './src/index.js';
|
|
251
|
+
</script>
|
|
252
|
+
</head>
|
|
253
|
+
<body>
|
|
254
|
+
<div id="vibe-target"></div>
|
|
255
|
+
<script type="module">
|
|
256
|
+
// Direct import
|
|
257
|
+
import useVibe from './src/index.js';
|
|
258
|
+
|
|
259
|
+
// Create a new vibe
|
|
260
|
+
const vibe = useVibe('HelloWorld');
|
|
261
|
+
|
|
262
|
+
// Basic injection test
|
|
263
|
+
document.querySelector("#vibe-target").innerHTML = vibe.describe();
|
|
264
|
+
</script>
|
|
265
|
+
</body>
|
|
266
|
+
</html>
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
3. Open this page in your browser and confirm that "hello world" is injected into the target element.
|
|
270
|
+
|
|
271
|
+
---
|
|
272
|
+
|
|
273
|
+
## Build and Deployment
|
|
274
|
+
|
|
275
|
+
- **Buildless ESM Approach**: This project uses a modern buildless ESM approach. TypeScript source files are directly imported during development, and TypeScript compiler is only used for type checking and generating type definitions. This avoids complex bundling processes while leveraging the native ESM support in modern browsers and Node.js environments.
|
|
276
|
+
|
|
277
|
+
```json
|
|
278
|
+
"scripts": {
|
|
279
|
+
"build": "tsc",
|
|
280
|
+
"typecheck": "tsc --noEmit"
|
|
281
|
+
}
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
- **Deployment**: Direct imports from source files are supported during development. For production, TypeScript is compiled to JavaScript while maintaining ESM imports. The package can be published to npm or JSR for easy consumption via ESM imports.
|
|
285
|
+
|
|
286
|
+
---
|
|
287
|
+
|
|
288
|
+
## Next Steps
|
|
289
|
+
|
|
290
|
+
1. **Vibe Check**: After completing the initial tests, review the results and gather feedback.
|
|
291
|
+
2. **Iterate**: Use feedback to refine functionality and integration.
|
|
292
|
+
3. **Expand**: Continue to develop additional features and tests, integrating further capabilities such as Fireproof, callAi, and more advanced micro-app interactions.
|
|
293
|
+
|
|
294
|
+
---
|
|
295
|
+
|
|
296
|
+
## License
|
|
297
|
+
|
|
298
|
+
This project is open source. See the LICENSE file for details.
|
|
299
|
+
|
|
300
|
+
---
|
|
301
|
+
|
|
302
|
+
## Contact
|
|
303
|
+
|
|
304
|
+
For questions, feedback, or contributions, please open an issue on the repository or contact the maintainers.
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
|
|
2
|
+
<!DOCTYPE html>
|
|
3
|
+
<html>
|
|
4
|
+
<head>
|
|
5
|
+
<title>useVibes Bookmarklet</title>
|
|
6
|
+
<meta charset="UTF-8">
|
|
7
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
8
|
+
<style>
|
|
9
|
+
body {
|
|
10
|
+
font-family: system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
|
|
11
|
+
max-width: 800px;
|
|
12
|
+
margin: 0 auto;
|
|
13
|
+
padding: 20px;
|
|
14
|
+
line-height: 1.6;
|
|
15
|
+
}
|
|
16
|
+
.bookmarklet {
|
|
17
|
+
display: inline-block;
|
|
18
|
+
padding: 8px 12px;
|
|
19
|
+
background: #4a8feb;
|
|
20
|
+
color: white;
|
|
21
|
+
text-decoration: none;
|
|
22
|
+
border-radius: 4px;
|
|
23
|
+
margin: 20px 0;
|
|
24
|
+
font-weight: bold;
|
|
25
|
+
}
|
|
26
|
+
.bookmarklet:hover {
|
|
27
|
+
background: #3a7edb;
|
|
28
|
+
}
|
|
29
|
+
code {
|
|
30
|
+
background: #f5f5f5;
|
|
31
|
+
padding: 2px 4px;
|
|
32
|
+
border-radius: 4px;
|
|
33
|
+
font-family: monospace;
|
|
34
|
+
}
|
|
35
|
+
pre {
|
|
36
|
+
background: #f5f5f5;
|
|
37
|
+
padding: 15px;
|
|
38
|
+
border-radius: 4px;
|
|
39
|
+
overflow-x: auto;
|
|
40
|
+
}
|
|
41
|
+
.note {
|
|
42
|
+
background: #fffde7;
|
|
43
|
+
border-left: 4px solid #ffeb3b;
|
|
44
|
+
padding: 10px 15px;
|
|
45
|
+
margin: 20px 0;
|
|
46
|
+
}
|
|
47
|
+
</style>
|
|
48
|
+
</head>
|
|
49
|
+
<body>
|
|
50
|
+
<h1>useVibes Bookmarklet</h1>
|
|
51
|
+
<p>This bookmarklet allows you to test useVibes on any website. Before using, you'll need to:</p>
|
|
52
|
+
<ol>
|
|
53
|
+
<li>Host the useVibes IIFE bundle on a web server or CDN</li>
|
|
54
|
+
<li>Get your API key for call-ai</li>
|
|
55
|
+
</ol>
|
|
56
|
+
|
|
57
|
+
<div class="note">
|
|
58
|
+
<strong>Important:</strong> You will need to edit this bookmarklet to replace <code>YOUR_API_KEY_HERE</code> with your actual API key, and update the script URL if needed.
|
|
59
|
+
</div>
|
|
60
|
+
|
|
61
|
+
<h2>Installation</h2>
|
|
62
|
+
<p>Drag this link to your bookmarks bar:</p>
|
|
63
|
+
<a class="bookmarklet" href="javascript:!function(){window.CALLAI_API_KEY="YOUR_API_KEY_HERE",alert("useVibes Injector: Click on any element to apply vibes to it.");let e=!0;function t(n){if(!e)return;n.preventDefault(),n.stopPropagation();const o=n.target,s=o.style.outline;o.style.outline="3px solid red";const i=prompt("Enter a prompt for useVibes:","Create a beautiful element with blue styling");i?useVibes(o,{prompt:i}).then((e=>{console.log("useVibes applied successfully!",e)})).catch((e=>{console.error("Error applying useVibes:",e),alert("Error: "+e.message)})):o.style.outline=s,e=!1,document.removeEventListener("click",t,!0)}!function(e,t){const n=document.createElement("script");n.src=e,n.onload=t,document.head.appendChild(n)}("https://unpkg.com/use-vibes@latest/lib/use-vibes.iife.js",(function(){"function"==typeof useVibes?document.addEventListener("click",t,!0):alert("useVibes library not loaded correctly!")}))}();">useVibes</a>
|
|
64
|
+
|
|
65
|
+
<h2>Usage Instructions</h2>
|
|
66
|
+
<ol>
|
|
67
|
+
<li>Drag the above link to your bookmarks bar</li>
|
|
68
|
+
<li>Navigate to any website</li>
|
|
69
|
+
<li>Click the bookmark</li>
|
|
70
|
+
<li>Click on any element you want to enhance</li>
|
|
71
|
+
<li>Enter your prompt when prompted</li>
|
|
72
|
+
<li>Watch as useVibes transforms the element</li>
|
|
73
|
+
</ol>
|
|
74
|
+
|
|
75
|
+
<h2>How to Customize</h2>
|
|
76
|
+
<p>To edit the bookmarklet with your API key:</p>
|
|
77
|
+
<ol>
|
|
78
|
+
<li>Right-click on the bookmarklet in your bookmarks bar</li>
|
|
79
|
+
<li>Select "Edit" or "Properties"</li>
|
|
80
|
+
<li>Find <code>CALLAI_API_KEY='YOUR_API_KEY_HERE'</code> and replace with your actual key</li>
|
|
81
|
+
<li>Find <code>useVibesScriptUrl='https://unpkg.com/use-vibes@latest/lib/use-vibes.iife.js'</code> and update if needed</li>
|
|
82
|
+
</ol>
|
|
83
|
+
|
|
84
|
+
<h2>Bookmarklet Code</h2>
|
|
85
|
+
<p>You can also manually create the bookmarklet with this code:</p>
|
|
86
|
+
<pre>javascript:!function(){window.CALLAI_API_KEY="YOUR_API_KEY_HERE",alert("useVibes Injector: Click on any element to apply vibes to it.");let e=!0;function t(n){if(!e)return;n.preventDefault(),n.stopPropagation();const o=n.target,s=o.style.outline;o.style.outline="3px solid red";const i=prompt("Enter a prompt for useVibes:","Create a beautiful element with blue styling");i?useVibes(o,{prompt:i}).then((e=>{console.log("useVibes applied successfully!",e)})).catch((e=>{console.error("Error applying useVibes:",e),alert("Error: "+e.message)})):o.style.outline=s,e=!1,document.removeEventListener("click",t,!0)}!function(e,t){const n=document.createElement("script");n.src=e,n.onload=t,document.head.appendChild(n)}("https://unpkg.com/use-vibes@latest/lib/use-vibes.iife.js",(function(){"function"==typeof useVibes?document.addEventListener("click",t,!0):alert("useVibes library not loaded correctly!")}))}();</pre>
|
|
87
|
+
</body>
|
|
88
|
+
</html>
|
|
89
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
javascript:!function(){window.CALLAI_API_KEY="YOUR_API_KEY_HERE",alert("useVibes Injector: Click on any element to apply vibes to it.");let e=!0;function t(n){if(!e)return;n.preventDefault(),n.stopPropagation();const o=n.target,s=o.style.outline;o.style.outline="3px solid red";const i=prompt("Enter a prompt for useVibes:","Create a beautiful element with blue styling");i?useVibes(o,{prompt:i}).then((e=>{console.log("useVibes applied successfully!",e)})).catch((e=>{console.error("Error applying useVibes:",e),alert("Error: "+e.message)})):o.style.outline=s,e=!1,document.removeEventListener("click",t,!0)}!function(e,t){const n=document.createElement("script");n.src=e,n.onload=t,document.head.appendChild(n)}("https://unpkg.com/use-vibes@latest/lib/use-vibes.iife.js",(function(){"function"==typeof useVibes?document.addEventListener("click",t,!0):alert("useVibes library not loaded correctly!")}))}();
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vibe interface represents the core functionality
|
|
3
|
+
*/
|
|
4
|
+
export interface Vibe {
|
|
5
|
+
/** The name of the vibe */
|
|
6
|
+
name: string;
|
|
7
|
+
/** The intensity level of the vibe */
|
|
8
|
+
intensity: number;
|
|
9
|
+
/** Set the intensity of the vibe */
|
|
10
|
+
setIntensity(level: number): void;
|
|
11
|
+
/** Get a description of the current vibe */
|
|
12
|
+
describe(): string;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Creates a new vibe with the given name
|
|
16
|
+
* @param name - Name for the vibe
|
|
17
|
+
* @returns A new Vibe instance
|
|
18
|
+
*/
|
|
19
|
+
export declare function createVibe(name: string): Vibe;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a new vibe with the given name
|
|
3
|
+
* @param name - Name for the vibe
|
|
4
|
+
* @returns A new Vibe instance
|
|
5
|
+
*/
|
|
6
|
+
export function createVibe(name) {
|
|
7
|
+
let intensityLevel = 5; // Default intensity
|
|
8
|
+
return {
|
|
9
|
+
name,
|
|
10
|
+
get intensity() {
|
|
11
|
+
return intensityLevel;
|
|
12
|
+
},
|
|
13
|
+
setIntensity(level) {
|
|
14
|
+
if (level < 0 || level > 10) {
|
|
15
|
+
throw new Error('Intensity must be between 0 and 10');
|
|
16
|
+
}
|
|
17
|
+
intensityLevel = level;
|
|
18
|
+
},
|
|
19
|
+
describe() {
|
|
20
|
+
return `${name} vibe at intensity ${intensityLevel}`;
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
}
|